在body里面绑定事件beforeunload = function(){/* statement */}
在页面上有个下载链接
<a href="http://xx.aspx?id=9acfffec-2254-df11-952364a">Download</a>
每次点击下载链接的时候beforeunload事件也会被触发,有什么办法能只在点击关闭按钮的时候触发而在点击下载的时候不触发该事件!
在页面上有个下载链接
<a href="http://xx.aspx?id=9acfffec-2254-df11-952364a">Download</a>
每次点击下载链接的时候beforeunload事件也会被触发,有什么办法能只在点击关闭按钮的时候触发而在点击下载的时候不触发该事件!
解决方案 »
- Node.JS
- 不使用 <input type="file" />,如何用javascript实现打开文件对话框的功能?
- window.open()如何控制父页面
- jquery @ 的作用
- BitmapCutter.Core发布到win2008上后不起作用
- 怎么用javascript动态改变标记<html> 的内容?
- 在javascript中命名分组的正则表达式是怎样写的,然后怎样利用命名替换或取出该命名级匹配的值?
- 如何对javascript数组进行索引查找?求助
- help!
- 哪位大神可以帮忙 sap ui 5的使用,数据绑定
- 大家知道目前国内都有什么js框架吗?
- 完善代码:上传文件前,在客户端判断文件大小和类型
<script type="text/javascript">
function LeavePage(){
if(document.attachEvent){
return "";
}
else{
return "Are you sure you want to navigate away from this page?";
}
}
</script>
</head><body onbeforeunload="return LeavePage();">
<a href="ddownload.aspx?uid=fdsds">Download</a>
function LeavePage(str){
if(str=="0")
{
return "Are you sure you want to navigate away from this page?";}
if(str=="1")
{
window.open("test.html");
}
}
</script>
</head>
<body onbeforeunload="return LeavePage(0)">
<a href="#" onClick="LeavePage(1)">关闭窗口</a>
还一种是这样的定义一个全局变量tag
在你的方法体内
var tag = true;
function checkout() {
if(tag) {
confirm("are you sure")
}
}在<input type="submit" onclick="tag = false" />