如何检查我是否使用jQuery离开另一个网站? [英] How to check I am leaving to another website using jQuery?

查看:121
本文介绍了如何检查我是否使用jQuery离开另一个网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户离开我们的网站浏览器的相同标签时,我想显示警报。我搜索并发现卸载事件,每次当用户离开或点击我们的网站链接时触发。

I want to show alert when user is leaving our website within same tab of the browser. I searched and found unload event, which triggers each time both when user is leaving or clicking our website link.

例如我在abc.com当我点击我的网站链接时,我不能有警报框。但是,当我在地址栏中写xyz.com时,我必须收到提醒框。

For example I'm at abc.com I must not got alert box when I'm clicking my site links. But I must got alert box when I'm writing xyz.com in address bar.

推荐答案

我现在看到你的问题没有,你不能这样做,你可以在你的域中的页面上做任何事情,你可以完全控制它,但你不能检测到你将进入一个不同的域,只是不可能,浏览器的行为,如果其他网站没有您的脚本,则您在浏览器上失去了控制权。

I see your question now, answer is NO, you can not do it, you can do whatever on your page in your domain, you have full control of it, but you can't not detect you are going to a different domain, just not possible, that the browser's behavior, and if the other site does not have your script, you have lost control on the browser.

例如,任何时候如果浏览器加载您的脚本,您都可以控制,一旦去不同的网站,浏览器卸载你的脚本,你能做什么?但是,如果你有脚本加载,你可以随时检查你当前的路径/域名。

For example, any time if the browser loads your script, you have all control, once it went to a different site, browser unload your script, what you can do? But sure, if you have scripts loaded, you can always check what is your current path/domain.

这篇关于如何检查我是否使用jQuery离开另一个网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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