我现在在关闭窗口时要去执行一段代码,具体代码如下:
<script language="javascript">
function function1(){
alert("aaa");
window.open("test.jsp");
}
</script>
<body onunload="javascript:function1();">
</body> 这样做没有效果啊。怎么才能实现在unload事件中调用javascript函数,在javascript函数中请求一个特定页面?
<script language="javascript">
function function1(){
alert("aaa");
window.open("test.jsp");
}
</script>
<body onunload="javascript:function1();">
</body> 这样做没有效果啊。怎么才能实现在unload事件中调用javascript函数,在javascript函数中请求一个特定页面?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">var xmlDoc;
var http_request=false;function initXMLHttp() {
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert("您需要升级您的浏览器!");
return false;
}
}
function function1(){
initXMLHttp();
var url = "http://xxx.xxx.xxx/xxx.jsp";
http_request.open("POST",url , false);
http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
http_request.send(null);
}
</script>
<body onunload="function1()">
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
function function1(){
window.open("http://www.cslg.cn/");
}
</script>
<body onunload="function1()">
</body>
</html>
第二个例子是在新窗口打开的,看看你的浏览器是不是过滤了弹出窗口