如何判断用户离开本页,转到了别的页面或者关闭本页了(难度大) 可以用程序给每一个连接填加一个onclick事件。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script for=document event=onclick> if(event.srcElement.tagName == "A" && event.srcElement.href != "")alert("是关闭不是刷新"); </script> <button onclick="javascript:location.href='http://www.baidu.com/?b';">ok</button><button onclick="javascript:location.replace('http://www.baidu.com/?b');">ok</button>如果跳转上上面的代码,就不行了。该怎么弄呢? 或者是下面这样的<input onclick="javascript:location.href='http://www.baidu.com/?b';" type=button value="test"><input onclick="javascript:location.href='http://www.baidu.com/?b';" value="test">还有这样类似这样的:<input onclick="test()" type=button value="test"><script>founction test(){location.href='http://www.baidu.com/?b';}</script>最后就是在form中action,submit提交的,这些都可以导致转到其他页面 主要是浏览器没有专门判断关闭的特有事件(onunload在刷新也会被触发),所以这个问题比较难,只好根据关闭浏览器的一些特征加以判断,比如用ALT+F4,比如点击X关闭:<script language="javascript">window.onbeforeunload = function() //author: meizz{ var n = window.event.screenX - window.screenLeft; var b = n > document.documentElement.scrollWidth-20; if(b && window.event.clientY < 0 || window.event.altKey) { window.event.returnValue = ""; //这里可以放置你想做的操作代码 }}</script> http://www.blogjava.net/TrampEagle/archive/2006/01/06/26829.html 怎么样用JS创建一个动态的添加点. DW问题!!高手帮忙! 求助,下拉框中如何删选数据? 救命啊,Openlayers问题!谁能解释下这句话嘛意思呀? 这样漂亮的效果是怎么做的?? 对高手来说是小问题了!!谁帮我啊?? 菜鸟求教啊 如何判断一个页面下载完成呢? 让某id的div隐藏后,但是还是在原来页面占着空间,如何让它不占位置?谢谢 【急】$( "*", document.body)的含义? DOM中怎么加入复杂节点? 请问如何实现浏览器的确认
if(event.srcElement.tagName == "A" && event.srcElement.href != "")alert("是关闭不是刷新");
</script>
<button onclick="javascript:location.replace('http://www.baidu.com/?b');">ok</button>
如果跳转上上面的代码,就不行了。
该怎么弄呢?
<input onclick="javascript:location.href='http://www.baidu.com/?b';" type=button value="test">
<input onclick="javascript:location.href='http://www.baidu.com/?b';" value="test">
还有这样类似这样的:
<input onclick="test()" type=button value="test">
<script>founction test(){location.href='http://www.baidu.com/?b';}</script>
最后就是在form中action,submit提交的,
这些都可以导致转到其他页面
<script language="javascript">
window.onbeforeunload = function() //author: meizz
{
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && window.event.clientY < 0 || window.event.altKey)
{
window.event.returnValue = ""; //这里可以放置你想做的操作代码
}
}
</script>