现在在Safari 3.1上卸载事件更具限制性? [英] unload event more restrictive now on Safari 3.1 ?

查看:76
本文介绍了现在在Safari 3.1上卸载事件更具限制性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用卸载活动。我有这个代码,

我已经抽象并制作成一个简单的测试用例

以下,它在主流浏览器上工作正常(IE5 +,Firefox) ,Opera)。

它也适用于3.1之前的所有Safari版本。


就好像他们故意做出改变来预防

中的一些操作卸载处理程序。有没有人听说过这样的限制?


这是测试案例:


< html>< body>

< a href =" destination.html">点击< / a>

< script>

var started = new Date( ).getTime();

var imj;

函数fin()

{

var diff =( new Date()。getTime() - started)/ 1000;

imj = new Image();

imj.src =" http://example.com /time.gif?"+diff;

// alert(" fin");

}

if(window.addEventListener )

window.addEventListener(''unload'',fin,false);

else if(window.attachEvent)

window.attachEvent (''onunload'',fin);

< / script>

< form>< input type = button value =" fin" onclick =" fin()">< / form>

< / body>< / html>


每次点击fin表单按钮,你看(通过一个http监视器

像Charles或Fiddler),图像加载发生在当前

时间增量,因为页面加载为缓存 - 破坏查询字符串。文件

获得404,但这没关系,当表单从表单按钮调用时,它正常工作。


如果你改为点击链接(或关闭浏览器),fin也称为

(通过取消注释警报确认),但图像加载不会发生。

I''ve been using the unload event for a long time. I have this code,
which I''ve abstracted and made into a stripped down simple test case
below, and it works fine on the major browsers (IE5+, Firefox, Opera).
It also works for all Safari versions before 3.1.

It''s as if they''ve deliberately made a change to prevent some actions in
the unload handler. Has anyone heard of such a restriction?

Here''s the test case:

<html><body>
<a href="destination.html">click</a>
<script>
var started=new Date().getTime();
var imj;
function fin()
{
var diff=(new Date().getTime()-started)/1000;
imj=new Image();
imj.src="http://example.com/time.gif?"+diff;
// alert("fin");
}
if(window.addEventListener)
window.addEventListener(''unload'',fin,false);
else if(window.attachEvent)
window.attachEvent(''onunload'',fin);
</script>
<form><input type=button value="fin" onclick="fin()"></form>
</body></html>

Each time you click the fin form button, you see (via a http monitor
like Charles or Fiddler) that the image load occurs with the current
time delta since page load as a cache-busting query string. The file
gets a 404, but that doesn''t matter, it''s working fine when fin is
called from the form button.

If you instead click the link (or close the browser), fin is also called
(confirmable by uncommenting the alert), but the image load doesn''t occur.

推荐答案

Stevo写道:
Stevo wrote:

我一直在使用unload事件很长时间。我有这个代码,

我已经抽象并制作成一个简单的测试用例

以下,它在主流浏览器上工作正常(IE5 +,Firefox) ,Opera)。

它也适用于3.1之前的所有Safari版本。


就好像他们故意做出改变来预防

中的一些操作卸载处理程序。有人听说过这样的限制吗?
I''ve been using the unload event for a long time. I have this code,
which I''ve abstracted and made into a stripped down simple test case
below, and it works fine on the major browsers (IE5+, Firefox, Opera).
It also works for all Safari versions before 3.1.

It''s as if they''ve deliberately made a change to prevent some actions in
the unload handler. Has anyone heard of such a restriction?



没有其他人受此影响吗?

Is nobody else affected by this?


6月16日上午10:29 *上午,Stevo< ; n ... @ mail.invalidwrote:
On Jun 16, 10:29*am, Stevo <n...@mail.invalidwrote:

我一直在使用unload事件很长一段时间。我有这个代码,

我已经抽象并制作成一个简单的测试用例

以下,它在主流浏览器上工作正常(IE5 +,Firefox) ,Opera)。

它也适用于3.1之前的所有Safari版本。


就好像他们故意做出改变来预防

中的一些操作卸载处理程序。有没有人听说过这样的限制?


这是测试案例:


< html>< body>

< a href =" destination.html">点击< / a>

< script>

var started = new Date( ).getTime();

var imj;

函数fin()

{

* * * * var diff =(new Date()。getTime() - started)/ 1000;

* * * * imj = new Image();

* * * * imj .src =" http://example.com/time.gif?" + diff;

// * * * alert(" fin");}


if(window.addEventListener)

* * * * window.addEventListener(''unload'',fin,false);

else if( window.attachEvent)

* * * * window.attachEvent(''onunload'',fin);

< / script>

< form>< input type = button value =" fin" onclick =" fin()">< / form>

< / body>< / html>


每次点击fin表单按钮,你看(通过一个http监视器

像Charles或Fiddler),图像加载发生在当前

时间增量,因为页面加载为缓存 - 破坏查询字符串。文件

获得404,但这没关系,当表单从表单按钮调用时,它正常工作。


如果你改为点击链接(或关闭浏览器),fin也称为

(通过取消注释警报确认),但图像加载不会发生。
I''ve been using the unload event for a long time. I have this code,
which I''ve abstracted and made into a stripped down simple test case
below, and it works fine on the major browsers (IE5+, Firefox, Opera).
It also works for all Safari versions before 3.1.

It''s as if they''ve deliberately made a change to prevent some actions in
the unload handler. Has anyone heard of such a restriction?

Here''s the test case:

<html><body>
<a href="destination.html">click</a>
<script>
var started=new Date().getTime();
var imj;
function fin()
{
* * * * var diff=(new Date().getTime()-started)/1000;
* * * * imj=new Image();
* * * * imj.src="http://example.com/time.gif?"+diff;
// * * *alert("fin");}

if(window.addEventListener)
* * * * window.addEventListener(''unload'',fin,false);
else if(window.attachEvent)
* * * * window.attachEvent(''onunload'',fin);
</script>
<form><input type=button value="fin" onclick="fin()"></form>
</body></html>

Each time you click the fin form button, you see (via a http monitor
like Charles or Fiddler) that the image load occurs with the current
time delta since page load as a cache-busting query string. The file
gets a 404, but that doesn''t matter, it''s working fine when fin is
called from the form button.

If you instead click the link (or close the browser), fin is also called
(confirmable by uncommenting the alert), but the image load doesn''t occur.



我正在尝试做同样的事情(在窗口卸载时加载图像)和

尝试一切无法想象的东西。看起来它不能完成,这对熟悉建筑的人来说可能是个问题。

的Safari。它确实适用于所有其他主流浏览器。如果有人

有解决方法,请告诉我们。谢谢。

I am trying to do the same thing (load the image on window unload) and
try everything imaginable to nothing works. It looks like it can''t be
done and this may be a question to someone familiar with architecture
of Safari. It does work on all other major browsers though. If anybody
has a fix for this please let us know. Thanks.


6月16日下午4:29 *,Stevo< n ... @ mail.invalidwrote:
On Jun 16, 4:29*pm, Stevo <n...@mail.invalidwrote:

我一直在使用卸载事件很长一段时间。我有这个代码,

我已经抽象并制作成一个简单的测试用例

以下,它在主流浏览器上工作正常(IE5 +,Firefox) ,Opera)。

它也适用于3.1之前的所有Safari版本。


就好像他们故意做出改变来预防

中的一些操作卸载处理程序。有没有人听说过这样的限制?


(...)


每次点击鳍形式按钮,你会看到(通过一个http监视器

像Charles或Fiddler一样)图像加载发生在页面加载后当前

时间增量作为缓存查询字符串。文件

获得404,但这没关系,当表单从表单按钮调用时,它正常工作。


如果你改为点击链接(或关闭浏览器),fin也称为

(通过取消注释警报确认),但图像加载不会发生。
I''ve been using the unload event for a long time. I have this code,
which I''ve abstracted and made into a stripped down simple test case
below, and it works fine on the major browsers (IE5+, Firefox, Opera).
It also works for all Safari versions before 3.1.

It''s as if they''ve deliberately made a change to prevent some actions in
the unload handler. Has anyone heard of such a restriction?

(...)

Each time you click the fin form button, you see (via a http monitor
like Charles or Fiddler) that the image load occurs with the current
time delta since page load as a cache-busting query string. The file
gets a 404, but that doesn''t matter, it''s working fine when fin is
called from the form button.

If you instead click the link (or close the browser), fin is also called
(confirmable by uncommenting the alert), but the image load doesn''t occur.






当窗口关闭时,我认为当处理程序获得
$时b $ b调用,Safari知道当前页面的屏幕图像不会再次刷新
,这可以解释为什么获取图片的触发器从未获取图片真的发生了。


当冲到另一个页面时,将图像插入到DOM中,这将迫使它加载......或者不加载它。 br />

此处图像已加载:请参阅: http:// tinyurl .com / 6lrv49


您可以改为使用同步XHR,SOP允许,

发送您的数据。 (如果图像请求只是为了发回一些

数据)

或者,您可以尝试请求< scriptinstead? (这是SOP免费的,

并且与屏幕更新无关。)


HTH,

- -Jorge。

Hi,

When the window is closed, I think that by the time the handler gets
called, Safari knows that the screen image of the current page is not
going to be refreshed again, this may explain why the trigger to fetch
the image never really happens.

When surfing away to another page, inserting the image into the DOM
migth be what forces it to load... or not.

Here the image gets loaded : See : http://tinyurl.com/6lrv49

You could instead use a synchronous XHR instead, S.O.P. permitting, to
send your data. (If the image request is being made just to send some
data back)
Or, you could try to request a <scriptinstead ? (it''s S.O.P.-free,
and has nothing to do with screen updates).

HTH,
--Jorge.


这篇关于现在在Safari 3.1上卸载事件更具限制性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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