相信很多朋友都遇到过,打开的网页明明都点击关闭浏览器的按钮了,还会提示一个弹窗出来问你需不需要关闭,网上很多下面的这种代码
window.onbeforeunload = onbeforeunload_handler;
function onbeforeunload_handler(){
var warning="你确定要离开vincent博客吗?";
return warning;
}
但是这种代码点击留在此页网页只能显示在当前页面!下面的代码就不同与这种了,点击留在此页后可以设置跳转到指定的页面!
/*vincent http://www.tbhyb.com*/
var exitsplashmessage = '你确定要离开vincent博客吗?';
var exitsplashpage = 'http://www.tbhyb.com';
/*vincent http://www.tbhyb.com*/
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
/*vincent http://www.tbhyb.com*/
function addClickEvent(a, i, func) {
if (typeof a[i].onclick != 'function') {
a[i].onclick = func;
}
}
/*vincent http://www.tbhyb.com*/
var theDiv = '
<div id="ExitSplashDiv" style="display:block; width:100%; height:100%; position:absolute; background:#FFFFFF; margin-top:0px; margin-left:0px;" align="center">';
theDiv = theDiv + '<iframe src="'+exitsplashpage+'" width="100%" height="100%" align="middle" frameborder="0"></iframe>';
theDiv = theDiv + '</div>
';
theBody = document.body;
if (!theBody) {
theBody = document.getElementById("body");
if (!theBody) {
theBody = document.getElementsByTagName("body")[0];
}
}
/*vincent http://www.tbhyb.com*/
var PreventExitSplash = false;
function DisplayExitSplash() {
if (PreventExitSplash == false) {
window.scrollTo(0, 0);
PreventExitSplash = true;
divtag = document.createElement("div");
divtag.setAttribute("id", "ExitSplashMainOuterLayer");
divtag.style.position = "absolute";
divtag.style.width = "100%";
divtag.style.height = "100%";
divtag.style.zIndex = "99";
divtag.style.left = "0px";
divtag.style.top = "0px";
divtag.innerHTML = theDiv;
theBody.innerHTML = "";
theBody.topMargin = "0px";
theBody.rightMargin = "0px";
theBody.bottomMargin = "0px";
theBody.leftMargin = "0px";
theBody.style.overflow = "hidden";
theBody.appendChild(divtag);
return exitsplashmessage;
}
}
/*vincent http://www.tbhyb.com*/
var a = document.getElementsByTagName('A');
for (var i = 0; i < a.length; i++) {
if (a[i].target !== '_blank') {
addClickEvent(a, i,
function() {
PreventExitSplash = true;
});
} else {
addClickEvent(a, i,
function() {
PreventExitSplash = false;
});
}
}
/*vincent http://www.tbhyb.com*/
disablelinksfunc = function() {
var a = document.getElementsByTagName('A');
for (var i = 0; i < a.length; i++) {
if (a[i].target !== '_blank') {
addClickEvent(a, i,
function() {
PreventExitSplash = true;
});
} else {
addClickEvent(a, i,
function() {
PreventExitSplash = false;
});
}
}
}
addLoadEvent(disablelinksfunc);
disableformsfunc = function() {
var f = document.getElementsByTagName('FORM');
for (var i = 0; i < f.length; i++) {
if (!f[i].onclick) {
f[i].onclick = function() {
PreventExitSplash = true;
}
} else if (!f[i].onsubmit) {
f[i].onsubmit = function() {
PreventExitSplash = true;
}
}
}
}
/*vincent http://www.tbhyb.com*/
addLoadEvent(disableformsfunc);
window.onbeforeunload = DisplayExitSplash;
本文章“好一站分类目录http://cgdyj.com/”编辑收录
关闭浏览器后出现的弹窗代码,支持跳转
来源:本站原创 浏览:365次 时间:2015-12-02
转载请注明-原文链接:关闭浏览器后出现的弹窗代码,支持跳转
- 上一篇: 什么是百度指数 百度指数查询怎么看
- 下一篇: 移动端web开发技巧与经验分享
推荐资讯
推荐站点
品晖设计(爱站帝) - 打造最简单好用的资源导航下载网
爱站帝(www.aizhandi.cn/)是提供最新绿色软件,精品源码,游戏资讯,技术教程,新闻资讯,精品资源,免费分享,热点事件,在线工具等,努力打造全网络爱好者优质服务的平台,让我们的生活更加精彩!初心仍在,一心分享精品资源文章,提供安全且绿色的文章,精彩文章尽在爱站帝。
aizhanju.cn3117站长服务平台
3117站长服务平台,专注于站长变现、交易支持。友链交换、购买、网站转让、买卖链接、软文发布等业务全覆盖。为站长提供互利共赢的
www.3117.cn我爱啦目录网 - 网站目录_分类目录_网站大全_网址导航_网址大全国内外网址大全应有尽有
我爱啦目录网人工收集编辑国内外网址大全,整理和收藏网站大全导航,让用户快速的找到自己需要的网站大全,用户还可以使用站内网站导航进去搜索国内外网站以及购物、团购、设计、视频、电影、军事、学习、交友、新闻等等的相关网址分类信息。
www.52la.cc免费分类信息网站大全_hao823_网址导航-中国好导航
hao823分类目录网站是免费收录各行业优秀的网站!提供网站分类信息检索、整理分类排序、按行业分类或关键词搜索查询;同时也是网站推广、网站排名、发布外链及提高网站权重等的分类目录平台。
www.hao823.com爱站聚网址大全_网址目录_上网导航_网站提交/登录入口
爱站聚是人工编辑的开放式网站分类目录,收录国内外、各行业优秀网站,旨在为用户提供网站分类目录检索、优秀网站参考、网站推广服务。
www.aizhanju.cn秀目录—网站目录。网站分类目录|网站目录|分类目录
秀目录网站是免费收录各行业优秀的网站!提供网站分类信息检索、整理分类排序、按行业分类或关键词搜索查询;同时也是网站推广、网站排名、发布外链及提高网站权重等的分类目录平台。
www.showmulu.com