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)閉當前頁面不彈出關(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)文章
js小數(shù)計算小數(shù)點后顯示多位小數(shù)的實現(xiàn)方法
下面小編就為大家?guī)硪黄猨s小數(shù)計算小數(shù)點后顯示多位小數(shù)的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05JS腳本實現(xiàn)動態(tài)給標簽控件添加事件的方法
這篇文章主要介紹了JS腳本實現(xiàn)動態(tài)給標簽控件添加事件的方法,結(jié)合實例形式分析了javascript添加事件監(jiān)聽的相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2016-06-06js鍵盤上下左右鍵怎么觸發(fā)function(實例講解)
這篇文章主要是對js鍵盤上下左右鍵怎么觸發(fā)function 進行了詳細的分析介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12JS中字符串切割為數(shù)組/數(shù)組拼接為字符串的代碼例子
這篇文章主要給大家介紹了關(guān)于JS中字符串切割為數(shù)組/數(shù)組拼接為字符串的相關(guān)資料,數(shù)組是JavaScript中最強大的數(shù)據(jù)結(jié)構(gòu),我們常常通過將字符串轉(zhuǎn)換為數(shù)組來解決許多算法,需要的朋友可以參考下2023-09-09