บทความนี้อธิบายเหตุการณ์และประเพณีที่สร้างขึ้นเมื่อ JS ปิดหน้าต่าง แบ่งปันสำหรับการอ้างอิงของคุณดังนี้:
/****************** ปิดหน้าต่างและส่งการประเมิน ****************/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 = 200; var layer = window.top.document.getElementById ("zz_layer"); if (layer! = null) {layer.parentNode.removeChild (เลเยอร์); } // เลเยอร์หน้ากากเลเยอร์ var layer = window.top.document.createElement ("div"); layer.id = "zz_layer"; layer.style.filter = "alpha (ความทึบ = 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 (เลเยอร์); // หน้าต่างการประเมินผล var newbox = document.getElementById ("kf_pj_div"); newbox.style.zindex = "9999"; newbox.style.display = "block"; newbox.style.width = width + "px"; newbox.style.height = ความสูง + "px"; newbox.style.border = "#565656 4px solid"; newbox.style.background = "#ffffff"; newbox.style.position = "สัมบูรณ์"; newbox.style.left = pagewidth/2 + "px"; newbox.style.top = (cltheight/2) + "px"; if (ความสูง/2> (cltheight/2)) {newbox.style.margintop = ( - (cltheight/2)) + "px"; } else {newbox.style.margintop = ( - ความสูง/2) + "px"; } if (width/2> (pagewidth/2)) {newbox.style.marginleft = ( - (pagewidth/2)) + "px"; } else {newbox.style.marginleft = ( - ความกว้าง/2) + "px"; } return "คุณยังไม่ได้แสดงความคิดเห็นเกี่ยวกับการบริการลูกค้าโปรดคลิก 'ยกเลิก' การจัดอันดับ!"; - ฟังก์ชั่น 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 = 200; var layer = window.top.document.getElementById ("zz_layer"); if (layer! = null) {// mask 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 (ความสูง/2> (cltheight/2)) {newbox.style.margintop = ( - (cltheight/2)) + "px"; } else {newbox.style.margintop = ( - ความสูง/2) + "px"; } if (width/2> (pagewidth/2)) {newbox.style.marginleft = ( - (pagewidth/2)) + "px"; } else {newbox.style.marginleft = ( - ความกว้าง/2) + "px"; }} window.onresize = mydiv_resize;สำหรับข้อมูลเพิ่มเติมเกี่ยวกับเนื้อหาที่เกี่ยวข้องกับ JavaScript โปรดตรวจสอบหัวข้อของไซต์นี้: "สรุปการทำงานของหน้าต่าง JavaScript และทักษะ", "สรุปทักษะการดำเนินงาน JSON ใน JavaScript", "JavaScript Switching เอฟเฟกต์พิเศษและทักษะสรุปทักษะการค้นหา JavaScript ของอัลกอริทึมและทักษะการสำรวจ JavaScript "และ" JavaScript Mathematical Operation Excage สรุป
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน