-2

I have seen location.href, window.open, window.location, etc for redirection.

  1. I want to know which is the best method and works on every device.
  2. One more thing if I have using setTimer and loads the script after loads the page elements which is the best method?

Please treat answer for both 1 and 2 question separately and thanks in advance.

nnnnnn
  • 147,572
  • 30
  • 200
  • 241
Matt Cutts
  • 11
  • 4
  • Please don't post an *entire* question in bold, that just makes it harder to read. Also, if you have two unrelated questions then please post them separately. `window.open()` opens a new window (oddly enough), so isn't really a redirection method and isn't comparable to setting the `location.href` of the *current* window. – nnnnnn Jul 07 '16 at 05:35

1 Answers1

0
window.location.href = 'URL';

is the standard implementation for changing the current window's location.

document.location is a (deprecated but still present) read-only string property, replaced by document.url.

window.location also affects to the frame,

the best form i found is:

parent.window.location.href

And the worse is:

parent.document.URL

I did a massive browser test, and some rare IE with several plugins get undefined with the second form.

Pieter de Vries
  • 825
  • 7
  • 18