在Firefox中更改window.location.href以响应onunload事件 [英] Changing window.location.href in Firefox in response to an onunload event

查看:185
本文介绍了在Firefox中更改window.location.href以响应onunload事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的JavaScript问题使用window.location.href,显然只影响Firefox(我使用3.6)。
$ b

通常window.location.href不会是只读的,这完美的FF:

  window.location.href =http:// google的.com /; 

然而,当我调用函数来响应onunload事件()时,这是行不通的如预期:

  function testThis(){
alert(1:+ window.location.href);
window.location.href =http://google.com/;
alert(2:+ window.location.href);
返回false;





在这两种情况下,警报都以FF显示页面的当前位置,没有做出改变。没有JavaScript错误,onunload事件成功调用函数,所以问题似乎是编辑或替换window.location.href的值。



I'已经尝试使用window.location,document.location.href,甚至尝试改变window.location.search。有没有可能是一个事件,特别是一个onunload事件,导致window.location.href成为只读?

解决方案

是,以防止恶意网页阻止用户离开。


I have a strange JavaScript problem using window.location.href, which apparently only affects Firefox (I'm using 3.6).

Normally window.location.href would not be read-only, and this works perfectly in FF:

window.location.href = "http://google.com/";

However, when I call a function in response to an onunload event (), this doesn't work as expected:

function testThis() {
    alert ("1: " + window.location.href);
    window.location.href = "http://google.com/";
    alert ("2: " + window.location.href);
    return false;
}

In both cases, the alert displays the current location of the page in FF, without making the change. There are no JavaScript errors, and the onunload event successfully calls the function, so the problem appears to be editing or replacing the value of window.location.href.

I've tried using window.location, document.location.href, even tried changing window.location.search. Is it possible that an event, specifically an onunload event, causes window.location.href to become read-only?

解决方案

Yes, to prevent malicious webpages from blocking the user from leaving.

这篇关于在Firefox中更改window.location.href以响应onunload事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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