开发者

Why is Firefox 6 ignoring my height, width, top and left settings in javascript window.open?

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>


Is showModalDialog() a valid member of window? I can't find it in the documentation.

Edit: Just did a quick Google search. showModalDialog is not a W3C standard and is not implemented in Firefox.

Edit: I'm wrong. Firefox caved and started supporting it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜