1. 程式人生 > >window.location.href 失效的解決辦法

window.location.href 失效的解決辦法

window.location.href 有時會失效..這又是萬惡的IE的BUG..

微軟上公佈3個解決方案的.

原文地址:http://support.microsoft.com/kb/190244/en-us


第一種:

在window.location.href 後面加上 window.event.returnValue = false;

如:

<a href="#" onclick="window.location.href='http://www.microsoft.com';
   window.event.returnValue=false;">

第二種:

把window.location.href寫成 JavaScript:window.location.href

如:

<a href="JavaScript:window.location.href='http://www.microsoft.com';">

第三種:

不寫 href 直接寫onlick .然後通過css樣式來控制滑鼠移上去顯示手型效果.

如:

<a onclick="window.location.href='http://www.microsoft.com';"   onmouseover="window.status='http://www.microsoft.com';"    onmouseout="window.status='';"   style="cursor:pointer; text-decoration:underline; color:blue;    font-family:times new roman">