为什么Firefox 6会忽略javascript window.open中的高度,宽度,顶部和左侧设置? [英] Why is Firefox 6 ignoring my height, width, top and left settings in javascript window.open?

查看:102
本文介绍了为什么Firefox 6会忽略javascript window.open中的高度,宽度,顶部和左侧设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以看到我的代码有什么问题吗?它在IE中的行为正常,但Firefox 6似乎忽略任何高度或宽度设置,我通过javascript window.open调用。我看不出任何明显的错误,但JavaScript不是我的第一语言,所以我可能会在这个地方做一个noob错误。



这个函数的目的打开一个以屏幕为中心的800x600窗口,并在IE和Mozilla浏览器中以模态方式显示。

 < html> 
< head>

< script language =javascripttype =text / javascript>
函数openWindow(pageURL,Title,w,h)
{
var left =(screen.width / 2) - (w / 2);
var top =(screen.height / 2) - (h / 2);
if(window.showModalDialog){
window.showModalDialog(pageURL,Title,'dialogWidth:'+ w +'px,dialogHeight:'+ h +'px,dialogTop:'+ top +'px ,dialogLeft:'+ left +',resizable = no');
} else {
window.open(pageURL,Title,toolbar = no,location = no,directories = no,status = no,menubar = no,scrollbars = yes,resizable = no,modal = yes,copyhistory = no,width =+ w +,height =+ h +,top =+ top +,left =+ left)
}
}

< / script>
< / head>
< body>
< / body>
< / html>

为了澄清一下,函数被设计用来测试ShowModalDialog的存在(假定只有IE支持它),并落入适当的window.open分支在所有支持W3C的window.open命令,实现模式选项的一切。这个想法是,如果ShowModalDialog被实现,那么它会使用,否则使用window.open与Modal选项。

showModalDialog中的分号,而不是逗号:

 < html> 
< head>

< script language =javascripttype =text / javascript>
函数openWindow(pageURL,Title,w,h)
{
var left =(screen.width - w)/ 2;
var top =(screen.height - h)/ 2;
var options;
if(window.showModalDialog){
options ='dialogwidth:'+ w +'; dialogheight:'+ h +'; dialogtop:'+ top +'; dialogleft:'+ left +';可调整大小=无';
console.log(options);
window.showModalDialog(pageURL,Title,options);
} else {
options =toolbar = no,location = no,directories = no,status = no,menubar = no,scrollbars = yes,resizable = no,modal = yes,copyhistory = no, width =+ w +,height =+ h +,top =+ top +,left =+ left;
console.log(window.open options:+ options);
window.open(pageURL,Title,options)
}
}

< / script>
< / head>
< body>
< / body>
< / html>


Can anybody see what's wrong with my code? It behaves properly in IE but firefox 6 seems to ignore any height or width settings that I pass through to the javascript window.open call. I can't see anything obviously wrong with it but javascript isn't my first language so I may be making a noob error somewhere in this.

The purpose of this function is to open an 800x600 window centered on the screen and displayed modally in both IE and Mozilla family browsers.

<html>
<head>

<script language="javascript" type="text/javascript">
    function openWindow(pageURL,Title,w,h) 
    {
        var left = (screen.width/2)-(w/2);
        var top = (screen.height/2)-(h/2);
        if (window.showModalDialog) {
            window.showModalDialog(pageURL,Title,'dialogWidth:' + w     + 'px,dialogHeight:'+ h + 'px,dialogTop:'+ top + 'px,dialogLeft:' + left + ',resizable=no');
        } else {
            window.open(pageURL,Title,"toolbar=no, location=no, directories=no,     status=no, menubar=no, scrollbars=yes,resizable=no,modal=yes,     copyhistory=no,width=" + w + ", height=" + h + ", top=" + top + ", left=" + left)
        }
    }   

</script>
</head>
<body>
<a href="javascript:openWindow('http://www.google.com','Google',800,600);">Launch</a>
</body>
</html>

Just to clarify a bit, the function is designed to test for the presence of ShowModalDialog (presuming that only IE supported it) and fall into the proper window.open branch in everything that supports the W3C window.open command which implements the "Modal" option. The idea being that if ShowModalDialog was implemented then it would use that otherwise use the window.open with the "Modal" option.

解决方案

Semi-colons, not commas, in showModalDialog:

<html>
<head>

<script language="javascript" type="text/javascript">
    function openWindow(pageURL,Title,w,h) 
    {
        var left = (screen.width - w) / 2;
        var top = (screen.height - h) / 2;
        var options;
        if (window.showModalDialog) {
            options = 'dialogwidth:' + w     + ';dialogheight:'+ h + ';dialogtop:'+ top + ';dialogleft:' + left + ';resizable=no';
            console.log(options);
            window.showModalDialog(pageURL, Title, options);
        } else {
            options = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes,resizable=no,modal=yes, copyhistory=no, width=" + w + ", height=" + h + ", top=" + top + ", left=" + left;
            console.log("window.open options: " + options);
            window.open(pageURL, Title, options)
        }
    }   

</script>
</head>
<body>
<a href="javascript:openWindow('http://www.google.com','Google',800,600);">Launch</a>
</body>
</html>

这篇关于为什么Firefox 6会忽略javascript window.open中的高度,宽度,顶部和左侧设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆