在网页程序中,
有时我们会希望使用者按下按钮后开启一个保持在原窗口前方的子窗口,
而在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. 华为机试题【13】-wave数组找字母游戏

    题目描述: Word Maze 是一个网络小游戏,你需要找到以字母标注的食物,但要求以给定单词字母的顺序吃掉.如上图,假设给定单词if,你必须先吃掉i然后才能吃掉f. 但现在你的任务可没有这么简单,你 ...

  2. ANN实现

    ANN核心数据结构: typedef struct  {     int input_n;                  /* number of input units */     int h ...

  3. PLSQL WEBSERVICES 发布

        一. 在Oracle EBS二次开发中,PL/SQL程序是开发人员使用频率最高的开发语言,同时也是大家最容易掌握的工具之一了,而我们也很希望将自己编写的PL/SQL程序发布为Web服务来提供给 ...

  4. 求二叉树深度和copy二叉树

    // operatorTree.cpp // 对树的操作 #include <iostream> #include <cstdio> // 二叉树表示法 typedef str ...

  5. 让App中加入LruCache缓存,轻松解决图片过多造成的OOM

    上次有过电话面试中问到Android中的缓存策略,当时模糊不清的回答,现在好好理一下吧. Android中一般情况下采取的缓存策略是使用二级缓存,即内存缓存+硬盘缓存->LruCache+Dis ...

  6. Android服务器——TomCat服务器的搭建

    Android服务器--TomCat服务器的搭建 作为一个开发人员,当然是需要自己调试一些程序的,这个时候本地的服务器就十分方便了,一般都会使用TomCat或者IIS服务器,IIS就比较简单了,其实t ...

  7. OpenGL OpenCV根据视差图重建三维信息

    代码如下: // disparity_to_3d_reconstruction.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" //Huan ...

  8. How tomcat works 读书笔记十四 服务器组件和服务组件

    之前的项目还是有些问题的,例如 1 只能有一个连接器,只能处理http请求,无法添加另外一个连接器用来处理https. 2 对容器的关闭只能是粗暴的关闭Bootstrap. 服务器组件 org.apa ...

  9. Spring 官网jar下载

    1,首先输入http://spring.io/进入Spring官网 2,点击project 栏,找到Spring framwork 3,点击reference 4,找到Distribution Zip ...

  10. ios项目开发汇总

    UI界面 iOS和Android 界面设计尺寸规范  http://www.alibuybuy.com/posts/85486.html iPhone app界面设计尺寸规范  http://www. ...