window.location.href不重定向 [英] window.location.href doesn't redirect

查看:164
本文介绍了window.location.href不重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个很多讨论的问题,但我无法弄清楚为什么它对我不起作用。

I know this is a question much discussed but I cant figure out why it does not work for me.

这是我的功能:

function ShowComments(){

 alert("fired");
 var movieShareId = document.getElementById('movieId');
 //alert("found div" + movieShareId.textContent || movieShareId.innerText);
 //alert("redirect location: /comments.aspx?id=" + movieShareId.textContent || movieShareId.innerText + "/");
 window.location.href = "/comments.aspx?id=" + movieShareId.textContent || movieShareId.innerText + "/";
 var newLocation = window.location;
 //alert("full location: " + window.location);

}

如果我没有注释警报或者我有mozilla的bugzilla打开它工作正常,否则它不会重定向到另一页。

If I have the alerts uncommented or if I have mozilla's bugzilla open it works fine, otherwise it does not redirect to the other page.

任何想法为什么?

推荐答案

如果您通过提交按钮调用此功能。这可能是浏览器不重定向的原因。它将运行函数中的代码,然后提交页面而不是重定向。在这种情况下,请更改按钮的类型标签。

If you are calling this function through a submit button. This may be the reason why the browser does not redirect. It will run the code in the function and then submit the page instead of redirect. In this case change the type tag of your button.

这篇关于window.location.href不重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆