惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
T
Threatpost
WordPress大学
WordPress大学
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
PCI Perspectives
PCI Perspectives
T
The Exploit Database - CXSecurity.com
Y
Y Combinator Blog
雷峰网
雷峰网
爱范儿
爱范儿
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
Simon Willison's Weblog
Simon Willison's Weblog
T
Tor Project blog
S
Securelist
宝玉的分享
宝玉的分享
L
LangChain Blog
O
OpenAI News
AI
AI
P
Privacy International News Feed
L
LINUX DO - 最新话题
D
DataBreaches.Net
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs
罗磊的独立博客
M
MIT News - Artificial intelligence
Security Archives - TechRepublic
Security Archives - TechRepublic
月光博客
月光博客
博客园 - 【当耐特】
T
Tailwind CSS Blog
C
Cybersecurity and Infrastructure Security Agency CISA
H
Help Net Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
Jina AI
Jina AI
The Last Watchdog
The Last Watchdog
K
Kaspersky official blog
Webroot Blog
Webroot Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Blog — PlanetScale
Blog — PlanetScale
MyScale Blog
MyScale Blog
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog

博客园 - sunrack

LINQ to SQL语句之Group By/Having和Exists/In/Any/All/Contains ASPxPopupControl does not show up in the right place C++/CLI托管字符串与非托管char数组的转换 程序员从初级到中级10个秘诀 Get JavaScript IntelliSense With DevExpress Client-Side Objects - v2010 vol 1 Grid Editing - Cascading Combo Boxes - sunrack ASPxRadioButtonList 报错解决办法 - sunrack - 博客园 本地连接属性“出现意外错误”的解决办法 - sunrack - 博客园 Bootstrap DotNetFX35SP1 in Visual Studio 2010 Windows Server 2008 共享策略 XtraPivotGrid Custom Summaries 手动注册 DevExpress 8.2.3 控件到 Visual Studio 工具箱 sn.exe error "Failed to generate a strong name key pair -- The keyset is not defined" Thread Tools Rate Thread javascript showModalDialog模态对话框使用说明 - sunrack - 博客园 entity framework 缓存干扰的数据不一致问题 Failed to load viewstate ? Typical problem, with an obvious solution. ViewState and Dynamic Control ASPxGridView 和 AJAX Extensions ToolBox 不兼容 ASPxCombobox Features
浅析JavaScript中的showModalDialog的实战应用
sunrack · 2010-05-24 · via 博客园 - sunrack

Posted on 2010-05-24 10:10  sunrack  阅读(398)  评论()    收藏  举报

IE提供的showModalDialog()方法是一个很好用的Web应用功能,虽然一般的网站应用不是很常见,但一旦涉及到企业应用级的Web开发则就很有用了。现在我用一个简单易懂的例子来说明一下:
这一应用需要两个web文件:
1、父窗口(也即用来控制弹出窗口的那个页面)
showModalDialog.html
<html>
<head>
<title>showModalDialog</title>
<script language="JavaScript">
<!--
//aInfo作为数组对象,将被showModalDialog传递出去
//也可用var oMyobject=new Object();
//oMyobject.firstProperty = value; oMyobject.lastProperty = value;的方式定义一个对象(firstProperty,lastProperty是自己按需定义的对象属性,可是任意取名并赋值)
var aInfo   = new Array(3);
aInfo[0] = "aaaaaaaaaaa";
aInfo[1] = "bbbbbbbbbbb";
aInfo[2] = "ccccccccccc";
var url = "dialog.html";
var sFeatures = "dialogWidth=500px;dialogHeight=500px;dialogLeft=0;dialogTop=0;";
/*sFeatures的各项可选参数:
*dialogWidth:弹出窗口的宽度;
*dialogHeight:弹出窗口的高度;
*dialogLeft:弹出窗口的左边距
*dialogTop:
*edge:sunken | raised
*center: yes|no|1|0|on|off
*dialogHide: yes|no|1|0|on|off
*help: yes|no|1|0|on|off
*resizable: yes|no|1|0|on|off
*scroll: yes|no|1|0|on|off
*status: yes|no|1|0|on|off
*unadorned: yes|no|1|0|on|off
*/
function showDialog(){
//弹出一个showModalDialog,并以returnValue来获取返回值
var returnValue = window.showModalDialog(url,aInfo,sFeatures);
if(returnValue!=null){
   //for(var i=0;i<returnValue.length;i++){
    //document.all.info.innerHTML = returnValue[i]+"<br>";
   //}
   //输出返回值
    document.all.info.innerHTML=returnValue;
}
//
}
//-->
</script>
</head>
<body>
<h3><a href="#" onclick="showDialog()">打开Dialog窗口</a></h3>
<div id="info"></div>
</body>
</html>
2、子窗口(即将被弹出的那个页面)
dialog.html
<html>
<head>
<title>Dialog</title>
</head>
<body>
<script language="JavaScript">
<!--
//获取父窗口传来的对象(本例中就是父页面中的“oInfo”数组对象,也可用“window”对象,以便对父页面进行操作。总之,只要是object类型就成。)
var args = window.dialogArguments;
if(args!=null){
//document.write(args);
for(var i=0;i<args.length;i++){
    document.writeln(args[i]+" "+(i+1)*10);
}
}else{
document.writeln("对不起,参数为空");
}
//向父窗口返回的值
window.returnValue = "这是子窗口返回来的值";
//-->
</script>
</body>
</html>
好了,运行showModalDialog.html即可看出其中的端倪来了。。。
通过这些工作,我实现了将值在父页面和子页面中的相互传递和处理。我想这也正是ms设计showModalDialog()方法的初衷之所在吧。当然,这个例子太简单了。但我的目的只是通过它了解showModalDialog的执行机制。实际应用中需要举一反三才行呢。(