JS關(guān)閉窗口時產(chǎn)生的事件及用法示例
本文實例講述了JS關(guān)閉窗口時產(chǎn)生的事件及用法。分享給大家供大家參考,具體如下:
/************ 關(guān)閉窗口,提交評價 **************/
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);
// 評價窗口
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 "您尚未對客服服務(wù)作出評價,請點擊‘取消'評分!";
};
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";
}
// 評價窗口
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動畫特效與技巧匯總》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運算用法總結(jié)》
希望本文所述對大家JavaScript程序設(shè)計有所幫助。
- JS打開新窗口的2種方式
- js打開新窗口方法整理
- JS打開新窗口防止被瀏覽器阻止的方法
- javascript打開新窗口同時關(guān)閉舊窗口
- 打開新窗口關(guān)閉當(dāng)前頁面不彈出關(guān)閉提示js代碼
- Flex調(diào)Javascript打開新窗口示例代碼
- JS關(guān)閉窗口與JS關(guān)閉頁面的幾種方法小結(jié)
- JavaScript無提示關(guān)閉窗口(兼容IE/Firefox/Chrome)
- IE JS無提示關(guān)閉窗口不提示的方法
- JavaScript實現(xiàn)自動彈出窗口并自動關(guān)閉窗口的方法
- JS關(guān)閉窗口或JS關(guān)閉頁面的幾種代碼分享
- JavaScript實現(xiàn)單擊網(wǎng)頁任意位置打開新窗口與關(guān)閉窗口的方法
相關(guān)文章
JavaScript之排序函數(shù)_動力節(jié)點Java學(xué)院整理
排序也是在程序中經(jīng)常用到的算法。這篇文章主要介紹了JavaScript之排序函數(shù),有興趣的可以了解一下2017-06-06
BootStrap模態(tài)框和select2合用時input無法獲取焦點的解決方法
在bootstrap的模態(tài)框里使用select2插件,會導(dǎo)致select2里的input輸入框沒有辦法獲得焦點,沒有辦法輸入。怎么解決這個問題呢?下面小編給大家?guī)砹薆ootStrap模態(tài)框和select2合用時input無法獲取焦點的解決方法,一起看看吧2017-09-09
javascript之DIV拖動類 支持在FF下拖動,調(diào)用簡單
javascript之DIV拖動類 支持在FF下拖動,調(diào)用簡單...2007-08-08
淺析JavaScript Array和string的轉(zhuǎn)換(推薦)
下面小編就為大家?guī)硪黄獪\析JavaScript Array和string的轉(zhuǎn)換(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05

