Javascript关闭浏览器窗口不弹出提示最新方法
作者: 李嘉 日期: 2009-07-23 21:54
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.
-------------------------------
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.
订阅
上一篇
返回
下一篇
标签:

非常实用的Windows 2003/XP重启IIS的批处理脚本 (2011-04-27 01:02)
服务器网管系列实用工具 - 监测某个程序运行并阻止,以阻止迅雷为例 (2011-04-25 23:07)
Javascript中Cookie如何跨域访问 (2011-02-07 23:17)
JQuery中监视Ajax的Json操作Error错误原因监控getJson (2011-02-06 23:48)
JavaScript中设为首页和加入收藏的代码(支持FireFox) (2011-01-15 23:41)
强烈推荐:Javascript最精简右下角弹出广告代码(兼容IE和FF) (2010-06-23 01:51)
网页HTML右侧浮动DIV层广告或在线客服图片框最佳代码(支持Firefox&IE) (2010-05-26 11:50)
Javascript中history.go(-1)和History.back()的区别是什么? (2010-04-30 04:08)
JS添加到收藏夹和设置为首页功能支持Firefox和IE——Add to Favorites (IE) / Bookmark (Firefox) Javascript (2010-04-11 06:19)