我有一个奇怪的 JavaScript 问题window.location.href
,它显然只影响 Firefox(我使用的是 3.6)。
通常window.location.href
不会是只读的,这在 Firefox 中完美运行:
window.location.href = "http://google.com/";
但是,当我调用函数以响应onunload
事件 ( <body onunload="testThis();">
) 时,这不会按预期工作:
function testThis() {
alert ("1: " + window.location.href);
window.location.href = "http://google.com/";
alert ("2: " + window.location.href);
return false;
}
在这两种情况下,警报都会在 Firefox 中显示页面的当前位置,而无需进行更改。没有 JavaScript 错误,并且onunload
事件成功调用了该函数,因此问题似乎是编辑或替换window.location.href
.
我试过使用window.location
, document.location.href
,甚至尝试改变window.location.search
. 一个事件,特别是一个事件,是否有可能onunload
导致window.location.href
只读?