Javascript关闭浏览器窗口不弹出提示最新方法

There is a hack for closing windows in IE without a warning. Although I've heard that it won't work for much longer.

<html>
<head>
<script>
function bye() {
self.opener = this;
self.close()
}
</script>
</head>
<body>
<a href="JavaScript: bye()">Bye bye</a>
</body>
</html>

An interesting trick but, it does not seem to work with the new XP SP2 or FF.
Although it may be the changes I just made to the Registry :D

注意:朋友说貌似这个方法在IE7&IE8中无效,经过我研究三个页面可以实现第二个页面自动关闭自己的功能,但不够完美,后续我会提供更完美的IE7&8 Hack方法。

--------------------------------------

I have an another idea.
Suppose, we have three web pages. (index.htm, index2.htm, pop.htm)

pop.htm : popup page.

index.htm : There we load a popup without any controllers, then redirecting parent window to index.htm.

index2.htm : On its UnLoad event it'll be redirected to itself.Also we can use an advertisement(s) here.

Problem seems to be little bit received.

But a new problem arises if we want to keep the popup being focused through its lifetime.After loading popup, and redirecting parent window, parent window will then focused.
How to keep popup focused all its life.

-------------------------------

For an internal, IE application, we use the following code to get rid of the parent window so we can open a new one without buttons and stuff:

function popViewer(currentWindow, mfSessionID, doSubmit) {
var windowName = buildWindowName(mfSessionID);
if(currentWindow.name == windowName){
currentWindow.focus();
if (doSubmit) {
document.body.style.cursor='wait';
process.submit();
}
}
else {
var newProcessURL = currentWindow.location.protocol + "//" + currentWindow.location.hostname + ":" + currentWindow.location.port + "/EnterpriseCommon/newprocesspageloader.jsp?windowname=" + windowName + "&origurl=" + escape(currentWindow.location);
var shell = new ActiveXObject("WScript.Shell");
shell.Run ("iexplore.exe " + newProcessURL, 7, false);
currentWindow.opener = null;
currentWindow.close();
}
}

We use the shell command so that we can start a new IE process because of some potential access violations we've seen when other windows have applets running. But you could just use a window.open to do the same thing. This, combined with a bunch of key code handling will minimize the opportunity for navigating in a way that wasn't intended. Of course, all of my users can still see my code.

Anyway, the reason I posted this is to point out that this works in XP SP2. Well... at least it does for me. :) ...and it seems like something that might come in handy for anyone building an internal application.

Hope this helps someone.
引用通告地址: 点击获取引用地址
标签: 脚本
评论: 2 | 引用: 0 | 阅读: 1624 | 打印 | 打包 | 转发
  • 1 
jltan [ 2009-07-24 14:46 网址 | 回复 | 编辑 删除 ]
我遇到了这样的case , 在IE 7 和 8 关掉弹出的窗口的时候, 如果是最后一个窗口就会出来一个确认框。期望这个框不出来。
加了这个还是和以前的一样。没有效果。
李嘉 [ 回复于2009-07-24 20:19 邮箱 网址 | 编辑 删除 ]
上面的方法是以前针对IE6进行hack实现不弹出提示的方法,目前IE7和IE8貌似还没有出来什么hack的方法,国外也没有爆出什么好的方法来。等以后爆出来好的方法我就贴上来。
  • 1 
发表评论
昵 称: 密 码:
网 址: 邮 箱:
验证码: 验证码图片 选 项:
头 像:
内 容:
  • 粗体
  • 斜体
  • 下划线
  • 插入图像
  • 超链接
  • 电子邮件
  • 插入引用