如何在所有浏览器上运行javascript?

时间:2011-06-25 13:12:11

标签: php javascript

我通过提高描述性来更新我的问题。

<script type="text/javascript">
    function myPopup2() {
        var iMyWidth;
        var iMyHeight;

        //half the screen width minus half the new window width (plus 5 pixel borders).
        iMyWidth = (window.screen.width/2) - (75 + 10);

        //half the screen height minus half the new window height (plus title and status bars).
        iMyHeight = (window.screen.height/2) - (100 + 50);

        window.open( "xyz.php" ,Store Record" ,"status=yes,height=300,width=350,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
    }
</script>

是与IE8不兼容的JavaScript。当我在Windows7上尝试使用FF 3.6.16时,它表现得很奇怪。有时它会在弹出窗口中显示代码。

谢谢,

1 个答案:

答案 0 :(得分:2)

您需要使用跨浏览器兼容的JavaScript。您可以通过feature detection实现此目的。实现这一目标的一个好方法是使用一个框架或库来完成大部分功能检测和交叉浏览,例如jQuery。还有其他像MooTools,Dojo,YUI,但它们没有像jQuery那样广泛使用,这是我推荐你的,它易于使用,易于学习,漂亮直观,而且相当快。

如果您的问题与您拥有的特定javascript有关,请使用该代码更新您的问题,以便我们可以帮助您实现跨浏览器兼容。