最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - window.location.href not working on IE - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited May 23, 2017 at 12:10 CommunityBot 11 silver badge asked Aug 16, 2013 at 17:14 VitoVito 7284 gold badges16 silver badges39 bronze badges 6
  • 1 Just use window.location. – user1477388 Commented Aug 16, 2013 at 17:14
  • stackoverflow.com/questions/10201809/… ? – twinlakes Commented Aug 16, 2013 at 17:16
  • For one, don't mix " and '. For two, there is no need to add strings that are hardcoded(juego.html"+'?modoJuego). window.location.href = "juego.html?modoJuego="+modoJuego+"&etapa="+etapa+"&rango="+rango; – David Starkey Commented Aug 16, 2013 at 17:16
  • What does your URL expand to? If any of your variables contain special or invalid characters you may need to wrap the right-hand side of your assignment in encodeURIComponent. – André Dion Commented Aug 16, 2013 at 17:27
  • windows.location produce the same result. The link of the second comment procduce the same result. I changed the string as suggested by David Starkey with the same result. Any other idea? – Vito Commented Aug 16, 2013 at 17:34
 |  Show 1 more comment

4 Answers 4

Reset to default 5

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.

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;

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.

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

Refer this question for information:

How to redirect to another webpage in JavaScript/jQuery?

发布评论

评论列表(0)

  1. 暂无评论