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)畫特效與技巧匯總》、《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打開新窗口的2種方式
- js打開新窗口方法整理
- JS打開新窗口防止被瀏覽器阻止的方法
- javascript打開新窗口同時(shí)關(guān)閉舊窗口
- 打開新窗口關(guān)閉當(dāng)前頁(yè)面不彈出關(guān)閉提示js代碼
- Flex調(diào)Javascript打開新窗口示例代碼
- JS關(guān)閉窗口與JS關(guān)閉頁(yè)面的幾種方法小結(jié)
- JavaScript無提示關(guān)閉窗口(兼容IE/Firefox/Chrome)
- IE JS無提示關(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è)任意位置打開新窗口與關(guān)閉窗口的方法
相關(guān)文章
JavaScript之排序函數(shù)_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
排序也是在程序中經(jīng)常用到的算法。這篇文章主要介紹了JavaScript之排序函數(shù),有興趣的可以了解一下2017-06-06
BootStrap模態(tài)框和select2合用時(shí)input無法獲取焦點(diǎn)的解決方法
在bootstrap的模態(tài)框里使用select2插件,會(huì)導(dǎo)致select2里的input輸入框沒有辦法獲得焦點(diǎn),沒有辦法輸入。怎么解決這個(gè)問題呢?下面小編給大家?guī)砹薆ootStrap模態(tài)框和select2合用時(shí)input無法獲取焦點(diǎn)的解決方法,一起看看吧2017-09-09
前端實(shí)現(xiàn)文件下載的幾種常用方式總結(jié)
這篇文章主要給大家介紹了關(guān)于前端實(shí)現(xiàn)文件下載的兩種常用方式,兩種方法均通過創(chuàng)建臨時(shí)URL并觸發(fā)下載實(shí)現(xiàn),文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-11-11
javascript之DIV拖動(dòng)類 支持在FF下拖動(dòng),調(diào)用簡(jiǎn)單
javascript之DIV拖動(dòng)類 支持在FF下拖動(dòng),調(diào)用簡(jiǎn)單...2007-08-08
淺析JavaScript Array和string的轉(zhuǎn)換(推薦)
下面小編就為大家?guī)硪黄獪\析JavaScript Array和string的轉(zhuǎn)換(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05

