Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript redirect, fastest way to do it? [closed]


I'm using javascript and localStorage to redirect.
But I have found that there are a lot of ways to do that. Here are a few:

document.location
document.location.href
window.open(url,how)
window.location
top.location
window.navigate() //not sure that this works

and the html meta way

<meta http-equiv="REFRESH" content="0;url=http://www.google.com"/>

I am just interested which of the above (or any other code) will redirect faster. As for info I will use it to redirect (to a website) google chrome when new tab is opened.

like image 335
AMD Avatar asked Feb 04 '13 13:02

AMD


People also ask

How do I close a redirect page?

From the drop-down menu select Settings then scroll down and click Advanced. In the Privacy & security section choose Content settings > Pop-ups and redirects then ensure that the Allowed option is turned off.

How do I automatically redirect a page after 5 seconds?

To redirect a webpage after 5 seconds, use the setInterval() method to set the time interval. Add the webpage in window. location. href object.

How do I redirect after a few seconds?

Complete HTML/CSS Course 2022 To redirect URL to a different website after few seconds, use the META tag, with the content attribute. The attributes set the seconds. The following is an example of redirecting current page to another website in 10 seconds. The content attribute sets the seconds.


1 Answers

Meta redirect is an awful hack and it breaks the back button. Never use it.

The rest is basically equivalent. window.location is most common.

The fastest way may be not to redirect from JS, but to use <a href> (with a click handler if you need to perform some operation before navigation), which e.g. enables browsers to prefetch DNS.

like image 122
Kornel Avatar answered Oct 18 '22 14:10

Kornel