ie8对于onmessage 事件的监听和取消

来源:互联网 发布:php 积分兑换 编辑:程序博客网 时间:2024/06/05 05:48
<script type="text/javascript" src="frontend/sea-modules/jquery/1.8.3/jquery-1.8.3.min.js"></script><script type="text/javascript" src="frontend/sea-modules/json/json2_2.js"></script><script type="text/javascript">function clientA(event){var url_param=event.data.split("|");var url=url_param[0];var param=JSON.parse(url_param[1]);$.ajax({type : "post",url : url,dataType : "json",async : false,data:param,success : function(response) {var resStr=JSON.stringify(response);event.source.postMessage(resStr,'*');window.removeEventListener('message', clientA);console.log(event, event.data);}});}function clientB(event){var url_param=event.data.split("|");var url=url_param[0];var param=JSON.parse(url_param[1]);$.ajax({type : "post",url : url,dataType : "json",data:param,async : false,success : function(response) {var resStr=JSON.stringify(response);event.source.postMessage(resStr,'*');window.detachEvent('onmessage', clientB);console.log(event, event.data);}});}if (typeof window.addEventListener != 'undefined') {//for ie9+    window.addEventListener('message', clientA, false);} else if (typeof window.attachEvent != 'undefined') {    //for ie8-     window.attachEvent('onmessage', clientB);}</script>

0 0
原创粉丝点击