javascript showModalDialog模態(tài)對(duì)話框使用說明
<script type="text/javascript">
function openWin(src, width, height, showScroll){
window.showModalDialog (src,"","location:No;status:No;help:No;dialogWidth:"+width+";dialogHeight:"+height+";scroll:"+showScroll+";");
}
</script>
例:<span style="CURSOR: pointer" onclick="openWin'http://www.dbjr.com.cn', '500px', '400px', 'no')">點(diǎn)擊</span>
2. 要注意的是,F(xiàn)irefox并不支持該功能,它支持的語法是
window.open
('openwin.html','newWin', 'modal=yes, width=200,height=200,resizable=no, scrollbars=no' );
3. 如何自動(dòng)判斷瀏覽器
<input type="button" value="打開對(duì)話框" onclick="showDialog('#')"/>
<SCRIPT LANGUAGE="JavaScript">
<!--
function showDialog(url)
{
if( document.all ) //IE
{
feature="dialogWidth:300px;dialogHeight:200px;status:no;help:no";
window.showModalDialog(url,null,feature);
}
else
{
//modelessDialog可以將modal換成dialog=yes
feature ="width=300,height=200,menubar=no,toolbar=no,location=no,";
feature+="scrollbars=no,status=no,modal=yes";
window.open(url,null,feature);
}
}
//-->
</SCRIPT>
4. 在IE中,模態(tài)對(duì)話框會(huì)隱藏地址欄,而在其他瀏覽器則不一定
【注意】在谷歌瀏覽器中,這個(gè)模態(tài)的效果也會(huì)失效。
5. 一般在彈出對(duì)話框的時(shí)候,我們都希望整個(gè)父頁面的背景變?yōu)橐粋€(gè)半透明的顏色,讓用戶看到后面是不可以訪問的
而關(guān)閉對(duì)話框之后又希望還原
這是怎么做到的呢?
///顯示某個(gè)訂單的詳細(xì)信息,通過一個(gè)模態(tài)對(duì)話框,而且屏幕會(huì)變顏色
function ShowOrderDetails(orderId) {
var url = "details.aspx?orderID=" + orderId;
//$("body").css("filter", "Alpha(Opacity=20)");
//filter:Alpha(Opacity=50)
$("body").addClass("body1");
ShowDetailsDialog(url, "600px", "400px", "yes");
$("body").removeClass("body1");
}
另外,有一個(gè)樣式表定義
.body1
{
background-color:#999999;
filter:Alpha(Opacity=40);
}
6. 如何在頁面之間傳遞數(shù)值
showModalDialog 傳值及刷新
(一)showModalDialog使用例子,父窗口向子窗口傳遞值,子窗口設(shè)置父窗口的值,子窗口關(guān)閉的時(shí)候返回值到父窗口.
farther.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<META content="EditPlus" name="Generator">
<META content="" name="Author">
<META content="" name="Keywords">
<META content="" name="Description">
<script language="javascript">
<!--
function openChild(){
var k = window.showModalDialog("child.html",window,"dialogWidth:335px;status:no;dialogHeight:300px");
if(k != null)
document.getElementById("txt11").value = k;
}
//-->
</script>
</HEAD>
<BODY>
<FONT face="宋體"></FONT>
<br>
傳遞到父窗口的值:<input id="txt9" type="text" value="3333333333333" name="txt9"><br>
返回的值:<input id="txt11" type="text" name="txt11"><br>
子窗口設(shè)置的值:<input id="txt10" type="text" name="txt10"><br>
<input id="Button1" onclick="openChild()" type="button" value="openChild" name="Button1">
</BODY>
</HTML>
child.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<META content="EditPlus" name="Generator">
<META content="" name="Author">
<META content="" name="Keywords">
<META content="" name="Description">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
</HEAD>
<BODY>
<FONT face="宋體"></FONT>
<br>
父窗口傳遞來的值:<input id="txt0" type="text" name="txt0"><br>
輸入要設(shè)置父窗口的值:<input id="txt1" type="text" name="txt1"><input id="Button1" onclick="setFather()" type="button" value="設(shè)置父窗口的值" name="Button1"><br>
輸入返回的值:<input id="txt2" type="text" name="txt2"><input id="Button2" onclick="retrunValue()" type="button" value="關(guān)閉切返回值" name="Button2">
<input id="Button3" onclick="" type="button" value="關(guān)閉刷新父窗口" name="Button3">
<script language="javascript">
<!--
var k=window.dialogArguments;
//獲得父窗口傳遞來的值
if(k!=null)
{
document.getElementById("txt0").value = k.document.getElementById("txt9").value;
}
//設(shè)置父窗口的值
function setFather()
{
k.document.getElementById("txt10").value = document.getElementById("txt1").value
}
//設(shè)置返回到父窗口的值
function retrunValue()
{
var s = document.getElementById("txt2").value;
window.returnValue=s;
window.close();
}
//-->
</script>
</BODY>
</HTML>
說明:
由于showModalDialog緩存嚴(yán)重,下面是在子窗口取消客戶端緩存的設(shè)置.也可以在服務(wù)器端取消緩存,參考:
http://adandelion.cnblogs.com/articles/252137.html
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
二)下面是關(guān)閉刷新父窗口的例子
farther.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
<!--
function openChild()
{
var k = window.showModalDialog("child.html",window,"dialogWidth:335px;status:no;dialogHeight:300px");
if(k == 1)//判斷是否刷新
{
alert('刷新');
window.location.reload();
}
}
//-->
</script>
</HEAD>
<BODY>
<br>
傳遞到父窗口的值:<input id="txt9" type="text" value="3333333333333" NAME="txt9"><br>
<input type="button" value="openChild" onclick="openChild()" ID="Button1" NAME="Button1">
</BODY>
</HTML>
child.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<META content="EditPlus" name="Generator">
<META content="" name="Author">
<META content="" name="Keywords">
<META content="" name="Description">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
</HEAD>
<BODY>
<FONT face="宋體"></FONT>
<br>
父窗口傳遞來的值:<input id="txt0" type="text" name="txt0"><br>
<input id="Button1" onclick="winClose(1)" type="button" value="關(guān)閉刷新父窗口" name="Button1">
<input id="Button2" onclick="winClose(0)" type="button" value="關(guān)閉不刷新父窗口" name="Button2">
<script language="javascript">
<!--
var k=window.dialogArguments;
//獲得父窗口傳遞來的值
if(k!=null)
{
document.getElementById("txt0").value = k.document.getElementById("txt9").value;
}
//關(guān)閉窗口返回是否刷新的參數(shù).
function winClose(isRefrash)
{
window.returnValue=isRefrash;
window.close();
}
//-->
</script>
</BODY>
</HTML>
說明
1.下面是取消客戶端緩存的:
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
也可以在服務(wù)器端取消緩存,參考:
http://adandelion.cnblogs.com/articles/252137.html
2.向父窗口傳遞闡述在ASP.NET中也可以是用aaa.aspx?id=1的方式傳遞.
3.不刷新父窗口的話在父窗口中直接這樣一來設(shè)置可以.
<script>
window.showModalDialog("child.html",window,"dialogWidth:335px;status:no;dialogHeight:300px");
</script>
4.在子窗口中若要提交頁面的話要加入:,這樣就不會(huì)打開新窗口了.
<head>
<base target="_self">
</HEAD>
- JS 模態(tài)對(duì)話框和非模態(tài)對(duì)話框操作技巧匯總
- 利用javascript打開模態(tài)對(duì)話框(示例代碼)
- JavaScript 實(shí)現(xiàn)模態(tài)對(duì)話框 源代碼大全
- 詳解AngularJS 模態(tài)對(duì)話框
- JS對(duì)話框_JS模態(tài)對(duì)話框showModalDialog用法總結(jié)
- 兩種WEB下的模態(tài)對(duì)話框 (asp.net或js的分別實(shí)現(xiàn))
- js模態(tài)對(duì)話框使用方法詳解
- js實(shí)現(xiàn)div模擬模態(tài)對(duì)話框展現(xiàn)URL內(nèi)容
- ModelDialog JavaScript模態(tài)對(duì)話框類代碼
- JavaScript實(shí)現(xiàn)模態(tài)對(duì)話框?qū)嵗?/a>
- js實(shí)現(xiàn)響應(yīng)按鈕點(diǎn)擊彈出可拖拽的非模態(tài)對(duì)話框完整實(shí)例【測試可用】
相關(guān)文章
js unicode 編碼解析關(guān)于數(shù)據(jù)轉(zhuǎn)換為中文的兩種方法
這篇文章主要介紹了js unicode 編碼解析關(guān)于數(shù)據(jù)轉(zhuǎn)換為中文的兩種方法,需要的朋友可以參考下2014-04-04js實(shí)現(xiàn)目錄鏈接,內(nèi)容跟著目錄滾動(dòng)顯示的簡單實(shí)例
下面小編就為大家?guī)硪黄猨s實(shí)現(xiàn)目錄鏈接,內(nèi)容跟著目錄滾動(dòng)顯示的簡單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-10-10cloneNode實(shí)現(xiàn)表格增加刪除效果
cloneNode實(shí)現(xiàn)表格增加刪除效果...2006-11-11js實(shí)現(xiàn)瀏覽器窗口大小被改變時(shí)觸發(fā)事件的方法
這篇文章主要介紹了js實(shí)現(xiàn)瀏覽器窗口大小被改變時(shí)觸發(fā)事件的方法,實(shí)例分析了window.onresize方法的使用技巧,需要的朋友可以參考下2015-02-02JavaScript獲得url所有參數(shù)鍵值表的方法
這篇文章主要介紹了JavaScript獲得url所有參數(shù)鍵值表的方法,實(shí)例分析了javascript操作URL的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03JavaScript中的對(duì)象的extensible屬性介紹
這篇文章主要介紹了JavaScript中的對(duì)象的extensible屬性介紹,JavaScript中,對(duì)象的extensible屬性用于表示是否允許在對(duì)象中動(dòng)態(tài)添加新的property,需要的朋友可以參考下2014-12-12基于JavaScript實(shí)現(xiàn)的插入排序算法分析
這篇文章主要介紹了基于JavaScript實(shí)現(xiàn)的插入排序算法,結(jié)合實(shí)例形式詳細(xì)分析了插入排序的原理、操作步驟及javascript相關(guān)實(shí)現(xiàn)技巧與注意事項(xiàng),需要的朋友可以參考下2017-04-04JavaScript實(shí)現(xiàn)自動(dòng)彈出窗口并自動(dòng)關(guān)閉窗口的方法
這篇文章主要介紹了JavaScript實(shí)現(xiàn)自動(dòng)彈出窗口并自動(dòng)關(guān)閉窗口的方法,可實(shí)現(xiàn)從頁面左側(cè)彈出窗口5秒后窗口向右移動(dòng)并消失的效果,涉及javascript針對(duì)頁面窗口及樣式的定義操作技巧,需要的朋友可以參考下2015-08-08