开发者

onBeforeUnload - how to call a server-side function without ajax

开发者 https://www.devze.com 2023-01-08 15:20 出处:网络
What I want to do: dis开发者_Python百科pose of a session upon detecting an \"OnBeforeUnload\" event in the client. I know it doesn\'t fire 100% of times (90% accuracy works fine for me)

What I want to do: dis开发者_Python百科pose of a session upon detecting an "OnBeforeUnload" event in the client. I know it doesn't fire 100% of times (90% accuracy works fine for me)

Here I saw how to do it with ajax, this system, however, breaks down with ajax: I can't use it at all.

I'm searching for ways of doing it


In short, you can't. You can't hold a user's browser hostage, which is what this would allow as an exploit if you could do what you want (e.g. redirecting on page exit). AJAX is your only option for a server-side call, and as you noted, that's unreliable as well.


I do not know if it is possible to do this during a "onBeforeUnload", but maybe you could try it.
Inject a image to you web page like:

<img src="yourscript?param1=value1&param2=value2" />

From the server side just return an empty image.


You're probably going to need to hook a synchronous call rather than AsynchronousJAX.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号