Firefox不兼容?

时间:2015-11-21 19:04:25

标签: javascript firefox compatibility

http://ahmedstudio.za.pl/firefoxerror/

它适用于Chrome,Opera,但与Firefox无法相处。 整个javascript的东西都没有应用。

这直接在我的javascript.js:

window.onload = function() {

        todo("body", 50);
        alert("alert!");

        setTimeout(function () {
            todo("body", 0);

        }, 1000)

}

function todo(element, size) {
     //blahblah
 }

3 个答案:

答案 0 :(得分:1)

即使它实际上没有解决您的问题,我也想分享关于用无效函数调用替换事件处理程序的发现。我写了这个小fiddle

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
  <script>
    jQuery(function(){
      $("body").on("load", function(){
        $(this).append("Should not run")
      });
    });
  </script>
</head>
<body onload="doesNotExist()">

</body>
</html>

Firefox,Explorer和Edge实际上替换了<body>事件处理程序。但是,Chrome会忽略onload="doesNotExist()"并执行上一个处理程序。

在标签汤的土地上,很难确定哪种解决方法是正确的,但它肯定是一个可以解释你症状的错误。

答案 1 :(得分:0)

function load() {
        //do stuff
}

和适当的

<body onload="load()"> </body>

答案 2 :(得分:0)

这在我身上运行良好。我甚至试图用这个片段创建一个虚拟页面,但无法复制它。这是片段。由于你共享的片段不包含jquery,我选择使用相同的代码。

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>

</head>
<body>
<script>
    window.onload = function(){
            _todo({
                a:'body',
                b:50,
                alertFrom:'window.onload'
            });
        setTimeout(function(){
             _todo({
                a:'body',
                b:0,
                alertFrom:'setTimeOut'
                  });   
            },1000);
        };

        function _todo(options){
            var a = options.a;
            var b = options.b;
            var c=options.alertFrom
             alert(c +" "+a +" "+b);
            };
 </script>
</body>
</html>

另请注意,功能后分号的重要性。 这里有几个快照 Alerting on load

Alerting after 1 sec