解决window.showModalDialog在Firefox无法支持
在网页程序中,
有时我们会希望使用者按下按钮后开启一个保持在原窗口前方的子窗口,
而在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无法支持的更多相关文章
- 【转载】解决window.showModalDialog 模态窗口中location 打开新窗口问题
来源: <http://bibipear.blog.sohu.com/143449988.html> 在我们的项目中,通常会用到showModalDialog 打开一个模态的子窗口,但是在 ...
- 高版本chrome不再支持window.showmodaldialog 的临时替换方案【用window.open】
接管别人的项目,因开发时用了showmodaldialog 导致最近很多用户chrome升级到最新之后 就无法弹窗了.原因是新版chrome[37+]不再支持showmodaldialog. show ...
- 兼容firefox,ie,谷歌,阻止浏览器冒泡事件,Firefox不支持event解决方法
兼容firefox,ie,谷歌,阻止浏览器冒泡事件,Firefox不支持event解决方法 // 获取事件function getEvent(){ if(window.event) {return w ...
- firefox并不支持selectSingleNode和selectNodes的解决方法
转自:http://qsrock.iteye.com/blog/209585 function test(){ var perid = document.thisForm.PerID.value; v ...
- window.frames[]在Firefox下无法兼容的解决方式
html代码段: <iframe id="fr" src="ProjectTree.aspx?IsFree=true&f=yes&IsCheckPr ...
- 解决chrome浏览器无法得到window.showModalDialog返回值的问题
父页面处理: function ProductList() { var TypeID = window.document.getElementById("Type").valu ...
- JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作
一.Iframe 篇 公共部分 //父对象得到子窗口的值 //ObjectID是窗口标识,ContentID是元素ID function GetValue(ObjectID,ContentID) { ...
- 总结JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作
一.Iframe 篇 //&&&&&&&&&&&&&&&&&&a ...
- 总结js(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作
http://hi.baidu.com/yashua839/blog/item/131fdb2fe547ef221f3089af.html一.Iframe 篇 //&&&&am ...
随机推荐
- Android For JNI(六)——交叉编译,NDK概述以及文件结构,编写自己的第一个JNI工程
Android For JNI(六)--交叉编译,NDK概述以及文件结构,编写自己的第一个JNI工程 终于回到我们的 android了,我们先要配置这个NDK的环境,但是之前,我们还要了解一下基本的术 ...
- SpriteBuilder中音频文件格式的需要注意的地方
就像在SpriteBuilder项目子目录中的其他资源文件一样,音频文件夹需要确定完整的文件夹路径. 并且如果音频文件输出格式为MP4,则扩展为.m4a(audio-only MPEG4)而不是.mp ...
- 【一天一道LeetCode】 #3 Longest Substring Without Repeating Characters
一天一道LeetCode (一)题目 Given a string, find the length of the longest substring without repeating charac ...
- OpenCV——颜色运算
#ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include <iostream> #include & ...
- 近期Mac上编译geany软件的总结
以前在Mac上装过port,后来改为brew.但是原来port装在/opt/local下的很多程序没删掉,path路径也没改,导致很多程序被重复安装,配置混乱.最后我痛下狠心用port uninsta ...
- M1卡区块控制位详解
M1卡区块控制位详解 Mifare 1S50/Mifare 1S70 每个扇区的密码和存取控制都是独立的,可以根据实际需要设定各自的密码及存取 控制.存取控制为4个字节,共32位,扇区中的每个块(包括 ...
- sso系统使用
一:什么是sso(single sign on) ? sso(单点登录系统)简单说就是客户端第一次访问应用1的时候,由于没有登录,会被引导到登录页面进行登录,如果登录校验通过,将返回一个认证信息tic ...
- 开源一个IE下获取XPath小工具,支持32/64位
背景是曾经友情支持了测试组一小段时间,发现他们使用selenium做页面的自动化测试,需要用到XPath,但IE下没有获取XPath的工具,只能在Firefox和chrome下获取,步骤还比较麻烦.而 ...
- Jquery getJSON方法分析
准备工作 ·Customer类 public class Customer { public int Unid { get; set; } public string Customer ...
- java设计模式--简单工厂
java设计模式--简单工厂 简单工厂不是一个标准的设计模式,但是很常用需要掌握. 在java应用开发中,要"面向接口编程". 1.java中接口的概念: 在java中接口是一种特 ...