1. 程式人生 > >iframe框架下的子父級頁面監控頁面關閉事件

iframe框架下的子父級頁面監控頁面關閉事件

1.子頁面監控父級tabs頁面關閉事件

兩種方式:

其一↓

var jq = top.jQuery;  
    jq("#tt").tabs({
          onBeforeClose: function(title,index){
            var target = this;
            if(title=="//此處為title名"){
                alert("aaa");
                AuditCashierConfig.cancelTrade();
            }
            return true;    // 阻止關閉
          }
        });
    // 若當前頁為收銀確認則預設選中
    if (jq("#tt").tabs('exists', "//此處為title名")){  
        jq("#tt").tabs('select', "//此處為title名");  
    } 


其二↓
$(window).unload(function (evt) {
		if (typeof evt == 'undefined') {
			evt = window.event;
		}
		if (evt) {
			var n = window.event.screenX - window.screenLeft; 
			var b = n > document.documentElement.scrollWidth-20;
			
			if(b && window.event.clientY < 0 || window.event.altKey){
				// 這個可以排除重新整理 關閉的時候觸發
				$.messager.confirm('確認','你確認想要關閉'+title,function(r){});
			} 
		}
	});

2.監控某頁面關閉或重新整理瀏覽器或瀏覽器頁面事件

window.onbeforeunload = onbeforeunload_handler;   // 關閉頁面之前
window.onunload = onunload_handler;   // 關閉頁面,此處加任何操作都不會影響關閉或者重新整理頁面
    function onbeforeunload_handler(){   
        var warning="確認退出?";           
        return warning;   
    }   
       
    function onunload_handler(){   
        var warning="謝謝光臨";   
        alert(warning);   
    }
// 排除重新整理頁面
window.onbeforeunload = function() //author: meizz    
  {    
    var n = window.event.screenX - window.screenLeft;    
    var b = n > document.documentElement.scrollWidth-20;    
    if(b && window.event.clientY < 0 || window.event.altKey)    
    {    
      alert("是關閉而非重新整理");    
       window.event.returnValue = ""; //這裡可以放置你想做的操作程式碼    
    }    
  } 
<span style="font-family:Helvetica, Tahoma, Arial, sans-serif;font-size:14px;color:#000000;font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.2px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">
</span>