在网页程序中,
有时我们会希望使用者按下按钮后开启一个保持在原窗口前方的子窗口,
而在IE中,我们可以使用showModalDialog来达成,
语法如下 :

vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])

范例:

window.showModalDialog("openwin.html","Arguments","dialogHeight: 200px; dialogWidth: 200px; dialogTop: 10px;dialogLeft: 10px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;");

但是.在Firefox中却没有showModalDialog这东西,
而在FireFox中我们只能使用window.open实现这样的功能,
window.open的语法如下 :

oNewWindow = window.open( [sURL] [, sName] [, sFeatures] [, bReplace])

只是,在Firefox下,window.open的参数中,sFeature多了一些功能设定,
而在FireFox下要让开启的窗口跟IE的showModalDialog一样的话,
只要在sFeatures中加个modal=yes就可以了,
范例如下:

window.open('openwin.html','newWin','modal=yes,width=200,height=200,resizable=no,scrollbars=no');

提到了子窗口,不得不提的就是子窗口跟母窗口间的交互操作,
因为我想很多人开启对话窗口应该都是为了将操作完的结果丢回去给母窗口...

如果是用showModalDialog的话,
在子窗口中要存取母窗口的函数的话,
要注意两个地方,
1.(母窗口中)开启窗口:

window.showModalDialog("openwin.html",self,'modal=yes,width=775,height=700,resizable=no,scrollbars=no');

在第二个参数(vArguments),改成self.

2.(子窗口中)调用母窗口的函数:

window.dialogArguments.ShowMsg(obj.value);

ShowMsg为母窗口中的函数.

而使用window.open的话,
则是要注意一个地方,
1.(子窗口中)调用母窗口的函数:

window.opener.ShowMsg(obj.value);

使用window.opener去接母窗口的对象.

如此一来,只要再透过navigator.appName去判断浏览器为何,
就可以写一个IE与FireFox兼容的函数...

例子如下:

在一个父窗口中打开一个子窗口,并把子窗口的值传递给父窗口

在父窗口中:

<script language="JavaScript">
function colorpick(obj){
if (window.showModalDialog!=null)//IE判断
{
var smd= window.showModalDialog("Default2.aspx","","dialogWidth:225px;dialogHeight:170px;status:no;help:no;scrolling=no;scrollbars=no");
if(smd!=null)
obj.style.background=rtn;
return;
}
else
{
this.returnAction=function(strResult){
if(strResult!=null)
obj.style.background=strResult;
}
window.open("Default2.aspx","","width=225,height=170,menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes");
return;
}

}
</script>

在子窗口中:

function act(RGB) {
if (window.showModalDialog!=null)//IE判断
{
parent.window.returnValue="#"+RGB;
window.close();//firefox不支持

}
else
{
window.opener.returnAction("#"+RGB);
top.close();//IE和FireFox都支持
}
}

解决window.showModalDialog在Firefox无法支持的更多相关文章

  1. 【转载】解决window.showModalDialog 模态窗口中location 打开新窗口问题

    来源: <http://bibipear.blog.sohu.com/143449988.html> 在我们的项目中,通常会用到showModalDialog 打开一个模态的子窗口,但是在 ...

  2. 高版本chrome不再支持window.showmodaldialog 的临时替换方案【用window.open】

    接管别人的项目,因开发时用了showmodaldialog 导致最近很多用户chrome升级到最新之后 就无法弹窗了.原因是新版chrome[37+]不再支持showmodaldialog. show ...

  3. 兼容firefox,ie,谷歌,阻止浏览器冒泡事件,Firefox不支持event解决方法

    兼容firefox,ie,谷歌,阻止浏览器冒泡事件,Firefox不支持event解决方法 // 获取事件function getEvent(){ if(window.event) {return w ...

  4. firefox并不支持selectSingleNode和selectNodes的解决方法

    转自:http://qsrock.iteye.com/blog/209585 function test(){ var perid = document.thisForm.PerID.value; v ...

  5. window.frames[]在Firefox下无法兼容的解决方式

    html代码段: <iframe id="fr" src="ProjectTree.aspx?IsFree=true&f=yes&IsCheckPr ...

  6. 解决chrome浏览器无法得到window.showModalDialog返回值的问题

    父页面处理: function ProductList() {   var TypeID = window.document.getElementById("Type").valu ...

  7. JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    一.Iframe 篇 公共部分 //父对象得到子窗口的值 //ObjectID是窗口标识,ContentID是元素ID function GetValue(ObjectID,ContentID) { ...

  8. 总结JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    一.Iframe 篇 //&&&&&&&&&&&&&&&&&&a ...

  9. 总结js(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    http://hi.baidu.com/yashua839/blog/item/131fdb2fe547ef221f3089af.html一.Iframe 篇 //&&&&am ...

随机推荐

  1. 《java入门第一季》之面向对象(如何使用帮助文档)

    1:打开帮助文档 2:点击显示,找到索引,看到输入框 3:知道你要找谁?以Scanner举例 4:在输入框里面输入Scanner,然后回车 5:看包 java.lang包下的类不需要导入包,其他的全部 ...

  2. Learning ROS forRobotics Programming Second Edition学习笔记(八)indigo rviz gazebo

    中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS forRobotics Pro ...

  3. Netfilter的使用和实现

    本文主要内容:Netfilter的原理和实现浅析,以及示例模块. 内核版本:2.6.37 Author:zhangskd @ csdn blog 概述 Netfilter为多种网络协议(IPv4.IP ...

  4. 本人在CSDN上的技术博客访问量突破了10万次,特此截图留念

                从 2011-11-16在CSDN开博至今,将近三年.  在近三年的时间里,本博的访问量于2014-07-01突破了10万次,单篇博文<软件开发高手须掌握的4大SQL精髓 ...

  5. LeetCode之旅(15)-Odd Even Linked List

    题目描述: Given a singly linked list, group all odd nodes together followed by the even nodes. Please no ...

  6. javascript访问html元素的内容(1)

    形如如下格式的html元素: <p id="my_p">I'm <strong>BIG</strong> panda!!!</p> ...

  7. 自定义UICollectionViewLayout 布局实现瀑布流

    自定义 UICollectionViewLayout 布局,实现瀑布流:UICollectionView和UICollectionViewCell 另行创建,这只是布局文件, 外界控制器只要遵守协议并 ...

  8. jQuery选择器面试题

    $("#myELement")    选择id值等于myElement的元素,id值不能重复在文档中只能有一个id值是myElement所以得到的是唯一的元素 $("di ...

  9. WebAPP移动前端性能优化规范和设计指导

  10. Python中urllib.urlencode中文字符的一个问题

    Django项目在访问Restful service时调用urllib.urlencode编码中文字符串时碰到下面这个错误. v = quote_plus(str(v)) UnicodeEncodeE ...