简体   繁体   中英

Page redirection not working in firefox using window.location but working in chrome

I wrote the following code to redirect the user to different pages on click. While the following code works fine in chrome, but it does not work in IE or firefox.

However, when i open the same buttons in new tab, they work just fine. But with single left click they do not work on any browser other than chrome.

I tried variations like, window.location='url' and window.location.assign(url) and window.location.href="url" but to no avail.

Please if someone can help me.

if (this.href == "http://www.successlabs.pk/download.php") { window.location.href= "http://www.successlabs.pk/download.php";} else if (this.href == "http://www.successlabs.pk/ContactUs.html") { window.location.href= "http://www.successlabs.pk/ContactUs.html";}

Thanks in advance.

this question is over a year old, but this is what worked for me:

function gotoPage(_link) {
   var _link = 'http://www.successlabs.pk/download.php';
   window.location(_link);
   return false;
}

It's possible that adding the 'return false;' line is what will make it work for you. This SO page explains why.

From the horse's mouth: https://developer.mozilla.org/en-US/docs/Web/API/Window/location

Example #1: Navigate to a new page

Whenever a new value is assigned to the location object, a document will be loaded using the URL as if location.assign() had been called with the modified URL. Note that security settings, like CORS, may prevent this to effectively happen.

 location.assign("http://www.mozilla.org"); // or location = "http://www.mozilla.org"; 

I have never used location.href before only the two examples given above - and they work in all browsers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM