[removed].href not working on IE

前端 未结 4 1895
陌清茗
陌清茗 2020-12-10 17:23

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\"+\'?modo         


        
相关标签:
4条回答
  • 2020-12-10 18:10

    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.

    0 讨论(0)
  • 2020-12-10 18:11

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

    Refer this question for information:

    How to redirect to another webpage in JavaScript/jQuery?

    0 讨论(0)
  • 2020-12-10 18:13

    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;
    
    0 讨论(0)
  • 2020-12-10 18:21

    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.

    0 讨论(0)
提交回复
热议问题