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
  • 378,754
  • 76
  • 643
  • 1,055
DiegoP.
  • 45,177
  • 34
  • 89
  • 107
  • 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,357
  • 2
  • 30
  • 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
  • 30,469
  • 8
  • 53
  • 60
1

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

dcaswell
  • 3,137
  • 2
  • 26
  • 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
  • 6,139
  • 3
  • 29
  • 56
The Mask
  • 17,007
  • 37
  • 111
  • 185