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 = '
';
theDiv = theDiv + '';
theDiv = theDiv + '
theDiv = theDiv + '';
theDiv = theDiv + '
';
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;
本文章“ACC分类目录ACCDIR.COM”编辑收录