2

I have this simple code that is working fine in every browser, but NOT in IE (every version).

 window.setTimeout('window.location = \"http://www.domain/modules/yobilab/copyright/classes/GO_overview.php?refNumb=".$RefNumb."\"', 3000);
            return false;

In every browser it will go to the right link

In IE instead it includes also the Link where it comes from, so it will become something like this:

http://www.domain/PAGEWHEREIWAS/modules/yobilab/copyright/classes/GO_overview.php?refNumb=something

Why it is doing so?

It generates a NOT FOUND error obviously.

Lightness Races in Orbit
  • 369,052
  • 73
  • 620
  • 1,021
DiegoP.
  • 43,947
  • 34
  • 88
  • 105
  • 1
    Doesn't look "simple" to me. What on earth does `\"http://www.domain/modules/yobilab/copyright/classes/GO_overview.php?refNumb=".$RefNumb."\"` mean in Javascript? – Lightness Races in Orbit Jun 09 '11 at 18:13
  • Sorry that is also a combination of PHP. Just look the javascript code and forget PHP – DiegoP. Jun 09 '11 at 18:15
  • 1
    No. Abstract the PHP out of the question entirely so that we can be sure it is not causing your problem. And provide a live testcase on [jsfiddle.net](http://jsfiddle.net) that demonstrates the issue. – Lightness Races in Orbit Jun 09 '11 at 18:15
  • 1
    That looks disturbingly like you are generating a JS string using PHP, and that JS string is being passed to `setTimeout` to be `eval`ed. Gargh! If you are going to dynamically build a URI in PHP, then store it in a variable so it is more readable. If you are going to use `setTimeout` then pass it a function, not a string. – Quentin Jun 09 '11 at 18:16
  • Did you try window.location.href = "http://url/to/goto"? – Anirudh Ramanathan Jun 09 '11 at 18:19

4 Answers4

12

Try using document.location instead of window.location.

Teddy
  • 18,047
  • 2
  • 29
  • 42
  • This solved the issue..I will accept your answer in 4 minutes =D Thanks everybody for the help! – DiegoP. Jun 09 '11 at 18:22
3

You need to create an anonymous function:

setTimeout(function() {window.location = "http://www.domain/modules/yobilab/copyright/classes/GO_overview.php?refNumb=12"}, 3000);
Candide
  • 29,406
  • 6
  • 51
  • 57
1

Add a "/" before the link, this makes IE understand that it is a relative link and forces the correct redirect.

dcaswell
  • 3,027
  • 2
  • 23
  • 25
Hellbent
  • 11
  • 1
0
function redirect() { 
     window.location.href = "http://www.domain/PAGEWHEREIWAS/modules/yobilab/copyright/classes/GO_overview.phprefNumb=something"; 

}

setTimeout(redirect, 3000);
ykaragol
  • 5,997
  • 3
  • 27
  • 54
The Mask
  • 16,429
  • 36
  • 107
  • 177