[Javascript]showModalDialog函數的使用

來源:互聯網
上載者:User

本範例可以實現彈出一個模態視窗,並示範了兩種接收和傳遞參數的方法,同時可以接受模態視窗返回的多個變數

 

showModalDialog協助可以參閱微軟MSDN http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/showmodaldialog.asp

AA.HTM


--------------------------------------------------------------------------------------------------------------------------

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>主介面</title>

</head>

<body>

<form id="getForm">    回傳值:<input type="text" id="getData" readOnly> <input type="text" id="getData1" readOnly>

</form>

<input type="button" value="開啟新視窗1" onClick="openWin1()">

<input type="button" value="開啟新視窗2" onClick="openWin2()">

<script language="JavaScript">   

function openWin1()   

{       

  var srcFile = "BB.htm";    //新視窗的文檔名稱       

  var winFeatures = "dialogHeight:300px; dialogLeft:200px;";       

  var obj = getForm;  //將form作為對象傳遞給新視窗              

  window.showModalDialog(srcFile, obj, winFeatures);   

}

function openWin2()   

{       

  var srcFile = "CC.htm";    //新視窗的文檔名稱       

  var winFeatures = "dialogHeight:300px; dialogLeft:200px;";       

  var obj = getForm.getData.value;  //將form作為對象傳遞給新視窗              

  var str=window.showModalDialog(srcFile, obj, winFeatures);   

  if(str!=null)

     document.getForm.getData.value = str;

}

</script>

</body>

</html>

BB.HTM

重要提示:你快顯視窗中調用的是ASPX檔案時,必須在Page_Load事件中加入以下代碼

Response.Expires = 0; Response.Cache.SetNoStore(); Response.AppendHeader("Pragma", "no-cache");

否則,每次彈出的頁面都是上一次的Cache,不會改變。


------------------------------------------------------------------------------------------------------------------------

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>新視窗BB</title>

</head>

<base target="_self"> <!--這句話非常重要,只要加上才能保證在快顯視窗中調用服務端代碼而不會再彈出一個新視窗-->

<body>

<form id="sendForm">    請輸入資料:

<input type="text" id="writeData">   

<input type="text" id="writeData1">

<input type="button" value="送回父視窗" onClick="send(sendForm.writeData.value,sendForm.writeData1.value);">

</form>

<script language="JavaScript">   

function send(val,val1)   

{       

    //取得父視窗傳過來的對象       

    var myObj = window.dialogArguments;       

    //賦值

    myObj.getData.value = val;

    myObj.getData1.value = val1;

    //關閉視窗       

    window.close();   

}

</script>

</body>

</html>

CC.HTM

------------------------------------------------------------------------------------------------------------------------

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>新視窗CC</title>

</head>

<base target="_self"> <!--這句話非常重要,只要加上才能保證在快顯視窗中調用服務端代碼而不會再彈出一個新視窗-->

<body>

<form id="sendForm">    請輸入資料:

<input type="text" id="writeData">   

<input type="button" value="送回父視窗" onClick="send(sendForm.writeData.value);">

</form>

<script language="JavaScript">   

function send(val)   

{        

    window.returnValue=val

    window.close();   

}

</script>

</body>

</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.