Vito
Vito

Reputation: 728

window.location.href not working on IE

I have a problem with window.location.href.

I'm trying to redirect to a page with the following code:

window.location.href = "juego.html"+'?modoJuego='+modoJuego+"&etapa="+etapa+"&rango="+rango;

It works perfectly on Firefox and Chrome, however in IE10 the browser freezes and I have to restart it. Sometimes it redirect to the desired page, but the parameters do not pass through. I have been looking for a solution, for example this one:

Window.Location Not Working In IE?

But the proposed solution do not work for me.

Do somebody know how to deal with this?

Upvotes: 7

Views: 49423

Answers (4)

Mahesh Padekar
Mahesh Padekar

Reputation: 59

Try window.location.replace(...) instead.

Refer this question for information:

How to redirect to another webpage in JavaScript/jQuery?

Upvotes: 1

user3012702
user3012702

Reputation: 41

For some reason IE only like full url.

I have te same problem and fix it adding the full url like this:

var baseURL = 'http://www.your_url.com/';

window.location.href = baseURL + "juego.html"+'?modoJuego='+modoJuego+"&etapa="+etapa+"&rango="+rango;

Upvotes: 4

André Dion
André Dion

Reputation: 21708

The problem is likely due to the value of your variables. If they contain special or invalid characters, those needs to be passed through encodeURIComponent before being assigned to window.location.href.

Upvotes: 5

losnir
losnir

Reputation: 1171

Use encodeURIComponent() to escape your url:

window.location.href = encodeURIComponent("juego.html?modoJuego=" + modoJuego + "&etapa=" + etapa + "&rango=" + rango);

Works fine on Firefox 23.0, Chrome 28.0.1500.95 and Internet Explorer 10.

Upvotes: 1

Related Questions