在window.onbeforeunload方法中打开新窗口

我想当关闭窗口时打开新网址,但是这样写不能实现,不知道为什么?请教!
<script language="javascript">
function  window.onbeforeunload()  { 
window.open("http://www.baidu.com/","a");
}
</script>

我测试了,放在网页什么地方都行。
下面代码可行!
[code="JavaScript"]

[/code]

[code="java"]window.onbeforeunload=function (){
alert("===onbeforeunload===");
if(event.clientX>document.body.clientWidth && event.clientY < 0 || event.altKey){
alert("你关闭了浏览器");
}else{
alert("你正在刷新页面");
}
}[/code]
这样

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)
{
alert("是关闭而非刷新");
window.event.returnValue = ""; //这里可以放置你想做的操作代码
}
}

补充一下:
更详细讲解onbeforeunload,onload(可以滤过)
http://blog.csdn.net/aidenliu/archive/2010/01/14/5189438.aspx

只有ie有效,确保没有其他的插件屏蔽弹出窗口。


window.unload=function(){ window.open("http://www.google.com/","_blank"); };



test



[url]https://developer.mozilla.org/en/DOM/window.onunload[/url]