user379888
user379888

Reputation:

Redirect user for specific time and return

My aim is to redirect user to a specific website for 18 seconds and then redirect back to my website. To accomplish this, I have written the code below. The problem I am facing was that the website started to redirect in a loop so I had to come up with a condition to avoid that. For this I have putted a check if the user is coming from my redirected website or not but now the redirection isnt working at all. Please guide. Thanks

Note: startupsandfinance is the domain name from which the user gets redirected back.

<script type='text/javascript'>
if !(( document.referrer.search(&quot;startupsandfinance&quot;))){


                        document.cookie=&quot;toURL&quot;+ &quot;=&quot; +escape(document.URL)+&quot;;path=/; domain=.mycsnippets.com&quot;;
                        document.cookie=&quot;refURL&quot;+ &quot;=&quot; +escape(document.referrer)+&quot;;path=/; domain=.mycsnippets.com&quot;;
                        this.location=&#39;http://www.startupsandfinance.com/welcome.htm&#39;;

}
</script>

Upvotes: 0

Views: 44

Answers (1)

Bergi
Bergi

Reputation: 664589

Please guide

  • if !(( is a syntax error
  • !search() will not work, since search returns -1 when nothing is found and the index else
  • Do not use this.location, but window.location
  • No need to use entity escapes inside <script> tags
  • Do never ever rely on referer, it can easily be spoofed or is disabled. Use cookies instead: Before redirecting set it, when coming back you can check it.

Upvotes: 2

Related Questions