作者 主題: 請教父視窗用window.open開子視窗後怎麼取得子視窗的值  (閱讀 2607 次)

0 會員 與 1 訪客 正在閱讀本文。

unetin

  • 懷疑的國中生
  • **
  • 文章數: 72
    • 檢視個人資料
原本的Javascript用showModalDialog取得子視窗的值,但被Chrome37 block掉這種用法了:

幾十個頁面調用Confirm這個js function:
if ( Confirm(2, 'Confirm Deletion ?') == 1 )  { goSubmit('DELRULES');}
if( Confirm(2,"Data Check OK, Apply them ?")==1 ) { goSubmit('APPLYDATA');}

Confirm的內容:
function Confirm(draw, msg)
{
    var msgObj=new Object();
    msgObj.draw=draw;
    msgObj.msg=msg;

    var strFeatures='dialogWidth=300px;dialogHeight=150px;center=yes;'
        strFeatures+='scrollbars=no;border=thin;help=no;status=no;edge=raised';
    return window.showModalDialog("confirm.htm", msgObj, strFeatures);
}


開子視窗內容:
    .....略....(幾個按鈕,按yes Answer=1 , 按No Answer=2 ,....)
    <script language="javascript">
        function Answer(answer)
        {
            window.returnValue=answer;
            window.close();
        }
    </script>

------------------------------------------------------------------------------------------
因為Chrome不能用,網路上說子視窗執行父視窗的function就可以把值回傳,所以我新的改成:

function openWin(targetfile, width, height)
{
    var winformat="";
    var returnVal;
    if ( !width ) { width=250; }
    if ( !height ) { height=200; }
    winformat=winformat+"width="+width+",";
    winformat=winformat+"height="+height+",";
    winformat=winformat+"left=420,";
    winformat=winformat+"top=280,";
    winformat=winformat+"titlebar=yes,";
    winformat=winformat+"menubar=no,";
    winformat=winformat+"toolbar=no,";
    winformat=winformat+"location=no,";
    winformat=winformat+"scrollbars=yes,";
    winformat=winformat+"resizable=yes,";
    winformat=winformat+"status=no,";

    var returnValue=window.open(targetfile, "new_win", winformat);
    window.callback = function(value) { returnVal=value; };
    return returnVal;

}

function Confirm(draw, msg)
{
    var msgObj=new Object();
    msgObj.draw=draw;
    msgObj.msg=msg;

   if (window.showModalDialog != undefined)
   {
    var strFeatures='dialogWidth=300px;dialogHeight=150px;center=yes;'
        strFeatures+='scrollbars=no;border=thin;help=no;status=no;edge=raised';
    return window.showModalDialog("confirm.htm", msgObj, strFeatures);
   }else{
    var ReturnChrome=openWin("confirm.htm", 300, 150);
    ReturnChrome.dialogArguments = msgObj;
    return ReturnChrome;
   }
}

子視窗內容:
    <script language="javascript">
        function Answer(answer)
        {
           if (window.showModalDialog != undefined)//Not Chrome
           {
            window.returnValue=answer;
           }else(
            opener.callback(answer);
           }
            window.close();
        }
    </script>
============================================================================
問題:
修改後的 子視窗的answer還是沒辦法在Chrome回傳,導致要回傳的ReturnChrome值有誤,請教該怎麼改?