解決chrome 不相容window.showModalDialog問題
阿新 • • 發佈:2018-12-14
在父視窗加上這麼一段程式碼:
<script type="text/javascript">
function showmodal()
{
alert("我是父親視窗")
if(window.showModalDialog == undefined){ //谷歌alert("dddddddddddddd")
window.myNewWindow = window.open(url,500,500); }else{
//IE window.showModalDialog(url, 530, 400);
}
}
</script>
在子視窗加上這麼一段程式碼:
<script type="text/javascript"> function returnMain() { if (window.opener != undefined) { alert("我是谷歌") parent=window.opener;獲得子視窗物件alert( parent); var deptRetNameArray=parent["deptRetNameArray"];獲得從父視窗傳過來的值; alert(deptRetNameArray+"谷歌"); } else { alert("我是IE"); var parentWindowObj = window.dialogArguments;獲得子視窗物件 var deptRetNameArray = parentWindowObj["deptRetNameArray"];獲得從父視窗傳過來的值; alert (deptRetNameArray+"IE"); } } </script>
父頁面 ########## father.html
<HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> </HEAD> <script type="text/javascript"> function showmodal() { alert("我是父親視窗") if(window.showModalDialog == undefined){ //谷歌alert("dddddddddddddd") window.myNewWindow = window.open("son.html",500,500); }else{ //IE window.showModalDialog("son.html", 530, 400); } } </script> <BODY> <INPUT id=button1 type=button value="open sub" name=button1 onclick="showmodal();"> </BODY> </HTML>
子頁面[html] view plaincopy ########## son.html
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
</HEAD>
<script type="text/javascript">
function returnMain()
{
if (window.opener != undefined) { alert("我是谷歌")
parent=window.opener;獲得子視窗物件alert( parent);
var deptRetNameArray=parent["deptRetNameArray"];獲得從父視窗傳過來的值;
alert(deptRetNameArray+"谷歌");
}
else { alert("我是IE");
var parentWindowObj = window.dialogArguments;獲得子視窗物件
var deptRetNameArray = parentWindowObj["deptRetNameArray"];獲得從父視窗傳過來的值;
alert (deptRetNameArray+"IE");
}
}
</script>
<BODY>
<INPUT id=button1 type=button value="return and close" name=button1 onclick="returnMain()">
</BODY>
</HTML>