前段时间做项目,用到了window.location.href 来页面跳转,不过这个方法很奇怪,有时候会不起作用,页面也会刷新一下,但是就是不会转向目标页面,google和baidu 都收效甚微,最后想出个解决办法,用下面这个就Ok了。呵呵只不过是耍个小聪明罢了,还希望各位看官不要见笑……

设置一个0秒的定时器: 

<script type="text/javascript">
var goUrl=function()
{
setTimeout(function(){ window.location = <a href="http://www.cnpublic.com">http://www.cnpublic.com</a>;}, 0);
}
</script>

浏览器区别:IE或者Firefox2.0.x下,可以使用window.location或window.location.href;

Firefox1.5.x下,只能使用window.location.
解决方法:使用window.location来代替window.location.href.

随便看看吧

多说几句
喜欢本文您可以任意转载。但请尊重老牛的劳动成果,转载请注明:
本文转载自:老牛的博客 — 勇于探索 [http://www.cnpublic.com]
本文链接: http://www.cnpublic.com/2009/06/windowlocationhref-invalid/

人过留名,雁过留声,大侠过留Comment。欢迎您拍砖!

无论怎样,希望这篇文章对您有帮助!

Trackback

2 comments untill now

  1. heheh

    [回复]

    wilensky 回复:

    哈哈

    [回复]

Add your comment now