1 $(function () {
2
//選擇器是選擇了easyui中的點擊連接,出現新的iframe
3 $("a[target='mainFrame']").click(function () { 4 iframes = document.getElementsByTagName("iframe"); 5 //即便iFrame的連接跳轉到另外一個頁面,但在他的上級頁面查看是頁面代碼時該iframe仍是原來的url,而這時候改iframe確實跳轉了 6 //因此,查看該iframe時固然是空白的了 7 //參考資料:http://zhidao.baidu.com/link?url=Ac9CF3QElK96J3z04BLq-NdT7NPrYN2--tURAZ3jeDRVTJ-a9e2RNA6UL1M4QinqSYkdmCiacQhxB08vS8kFkq&qq-pf-to=pcqq.c2c 8 9 //下面是對上面這句話的試驗 10 if (iframes[0].contentWindow.location.href == "about:blank") { 11 //top.location.href = "Index.ashx"; 12 //top.location.reload(); 13 alert("1"); 14 } 15 16 //因而給iframe添加「加載完成」的事件 17 iframes[0].onload = function () { 18 //alert("2"); //試驗可否進入 19 //結果,先alert1,後alert2 20 21 //alert(parent.iframes[0].contentWindow.location.href); //試驗href的值,正是跳轉後的值 22 //若是iframe跳轉後的url是iframe的父容器(這裏也就是瀏覽器,由於只有一層iframe)的url,則把最外層容器定位爲Index.ashx 23 if (parent.iframes[0].contentWindow.location.href.indexOf("Index.ashx")) { 24 top.location.href = "Index.ashx"; 25 } 26 } 27 28 }); 29 30 });