window.location.href IE下跳转失效的解决方法

复制代码 代码如下:

  <a href="javascript:void(0)" >GoNext</a>

  $("a").click(function(){

  window.location.href = "xxx.html";

  })

  代码如上,在IE下,特别是在IE6中,点击超链接之后,浏览器并没有发生跳转行为。

  原因可能是因为在href中的javascript:void(0)阻止的事件行为,解决方法如下:

  1.在onclick事件中加return false来阻止冒泡:

  

复制代码 代码如下:

  $("a").click(function(){

  window.location.href = "xxx.html";

  reutrn false;

  })

  2.延迟100毫秒

  

复制代码 代码如下:

  $("a").click(function(){

  setTimeout(function(){

  window.location.href = "xxx.html";

  },100);

  })