JS關(guān)閉窗口時(shí)產(chǎn)生的事件及用法示例
本文實(shí)例講述了JS關(guān)閉窗口時(shí)產(chǎn)生的事件及用法。分享給大家供大家參考,具體如下:
/************ 關(guān)閉窗口,提交評(píng)價(jià) **************/
window.onbeforeunload = function(){
var pageWidth = Math.max(window.top.document.body.scrollWidth, window.top.document.documentElement.scrollWidth);
var pageHeight = Math.max(window.top.document.body.scrollHeight, window.top.document.documentElement.scrollHeight);
var cltHeight = Math.max(window.top.document.body.clientHeight, window.top.document.documentElement.clientHeight);
var width = 400 ;
var height = 200 ;
var layer = window.top.document.getElementById("zz_layer");
if (layer != null) {
layer.parentNode.removeChild(layer);
}
// 遮罩層
var layer= window.top.document.createElement("div");
layer.id = "zz_layer";
layer.style.filter = "alpha(opacity=38)";//ie
layer.style.opacity = "0.38";//ff
layer.style.width = pageWidth + "px";
layer.style.height = pageHeight + "px";
layer.style.position= "absolute";
layer.style.top = 0;
layer.style.left = 0;
layer.style.backgroundColor = "#000";
layer.style.zIndex = "9998";
window.top.document.body.appendChild(layer);
// 評(píng)價(jià)窗口
var newbox = document.getElementById("KF_PJ_DIV");
newbox.style.zIndex = "9999";
newbox.style.display = "block";
newbox.style.width = width + "px";
newbox.style.height = height + "px";
newbox.style.border = "#565656 4px solid";
newbox.style.background = "#FFFFFF";
newbox.style.position = "absolute";
newbox.style.left = pageWidth/2 + "px";
newbox.style.top = (cltHeight/2) + "px";
if(height/2 > (cltHeight/2)){
newbox.style.marginTop = ( - (cltHeight/2)) + "px";
}else{
newbox.style.marginTop = ( - height/2) + "px";
}
if(width/2 > (pageWidth/2)){
newbox.style.marginLeft = ( - (pageWidth/2)) + "px";
}else{
newbox.style.marginLeft = ( - width/2) + "px";
}
return "您尚未對(duì)客服服務(wù)作出評(píng)價(jià),請(qǐng)點(diǎn)擊‘取消'評(píng)分!";
};
function mydiv_resize(){
var pageWidth = Math.max(window.top.document.body.scrollWidth, window.top.document.documentElement.scrollWidth);
var pageHeight = Math.max(window.top.document.body.scrollHeight, window.top.document.documentElement.scrollHeight);
var cltHeight = Math.max(window.top.document.body.clientHeight, window.top.document.documentElement.clientHeight);
var cltWidth = Math.max(window.top.document.body.clientWidth, window.top.document.documentElement.clientWidth);
var width = 400 ;
var height = 200 ;
var layer = window.top.document.getElementById("zz_layer");
if (layer != null) {
// 遮罩層
layer.style.width = pageWidth + "px";
layer.style.height = pageHeight + "px";
}
// 評(píng)價(jià)窗口
var newbox = document.getElementById("KF_PJ_DIV");
newbox.style.left = cltWidth/2 + "px";
newbox.style.top = (cltHeight/2) + "px";
if(height/2 > (cltHeight/2)){
newbox.style.marginTop = ( - (cltHeight/2)) + "px";
}else{
newbox.style.marginTop = ( - height/2) + "px";
}
if(width/2 > (pageWidth/2)){
newbox.style.marginLeft = ( - (pageWidth/2)) + "px";
}else{
newbox.style.marginLeft = ( - width/2) + "px";
}
}
window.onresize = mydiv_resize;
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript窗口操作與技巧匯總》、《JavaScript中json操作技巧總結(jié)》、《JavaScript切換特效與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript動(dòng)畫(huà)特效與技巧匯總》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
- JS打開(kāi)新窗口的2種方式
- js打開(kāi)新窗口方法整理
- JS打開(kāi)新窗口防止被瀏覽器阻止的方法
- javascript打開(kāi)新窗口同時(shí)關(guān)閉舊窗口
- 打開(kāi)新窗口關(guān)閉當(dāng)前頁(yè)面不彈出關(guān)閉提示js代碼
- Flex調(diào)Javascript打開(kāi)新窗口示例代碼
- JS關(guān)閉窗口與JS關(guān)閉頁(yè)面的幾種方法小結(jié)
- JavaScript無(wú)提示關(guān)閉窗口(兼容IE/Firefox/Chrome)
- IE JS無(wú)提示關(guān)閉窗口不提示的方法
- JavaScript實(shí)現(xiàn)自動(dòng)彈出窗口并自動(dòng)關(guān)閉窗口的方法
- JS關(guān)閉窗口或JS關(guān)閉頁(yè)面的幾種代碼分享
- JavaScript實(shí)現(xiàn)單擊網(wǎng)頁(yè)任意位置打開(kāi)新窗口與關(guān)閉窗口的方法
相關(guān)文章
js小數(shù)計(jì)算小數(shù)點(diǎn)后顯示多位小數(shù)的實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇js小數(shù)計(jì)算小數(shù)點(diǎn)后顯示多位小數(shù)的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-05-05
JS腳本實(shí)現(xiàn)動(dòng)態(tài)給標(biāo)簽控件添加事件的方法
這篇文章主要介紹了JS腳本實(shí)現(xiàn)動(dòng)態(tài)給標(biāo)簽控件添加事件的方法,結(jié)合實(shí)例形式分析了javascript添加事件監(jiān)聽(tīng)的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-06-06
js鍵盤(pán)上下左右鍵怎么觸發(fā)function(實(shí)例講解)
這篇文章主要是對(duì)js鍵盤(pán)上下左右鍵怎么觸發(fā)function 進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12
js跨瀏覽器的事件偵聽(tīng)器和事件對(duì)象的使用方法
這篇文章主要介紹了js跨瀏覽器的事件偵聽(tīng)器和事件對(duì)象的使用方法,需要的朋友可以參考下2015-12-12
JS中字符串切割為數(shù)組/數(shù)組拼接為字符串的代碼例子
這篇文章主要給大家介紹了關(guān)于JS中字符串切割為數(shù)組/數(shù)組拼接為字符串的相關(guān)資料,數(shù)組是JavaScript中最強(qiáng)大的數(shù)據(jù)結(jié)構(gòu),我們常常通過(guò)將字符串轉(zhuǎn)換為數(shù)組來(lái)解決許多算法,需要的朋友可以參考下2023-09-09

