0

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.

Salik
  • 508
  • 6
  • 17
  • 35

2 Answers2

1

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.

Community
  • 1
  • 1
Adam
  • 1,546
  • 2
  • 18
  • 23
0

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

Michael Coxon
  • 5,311
  • 1
  • 24
  • 51
  • `location.assign` does not help either. why does it work just fine when i right click and open it in new tab? – Salik Apr 28 '15 at 11:12