0

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

It works in chrome, opera but doesn't get along with Firefox. The whole javascript thing is not applying.

This is directly in my javascript.js:

window.onload = function() {
 todo("body", 50);
 alert("alert!");
 setTimeout(function () {
 todo("body", 0);
 }, 1000)
}
function todo(element, size) {
 //blahblah
 }
asked Nov 21, 2015 at 19:04
9
  • Can you link to the whole page? Are you getting any error in the console? Commented Nov 21, 2015 at 19:05
  • "ReferenceError: loading is not defined" Commented Nov 21, 2015 at 19:07
  • 1
    There is no loading identifier in the code that you have shown. Do you use that in the todo function? Commented Nov 21, 2015 at 19:10
  • 1
    What happens if you remove the onload="loading()" from your <body> tag? Commented Nov 21, 2015 at 19:43
  • 1
    You are replacing all onload handlers with an invalid function call. When trying to fix the mess, it's possible that other browsers refuse to redefine onload and the rest of the code works by pure chance. Commented Nov 21, 2015 at 19:53

3 Answers 3

1

Even if it doesn't actually solve your problem I'd like to share my findings about replacing event handlers with invalid function calls. I've composed this little 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 and Edge actually replace the <body> event handler. However, Chrome ignores the onload="doesNotExist()" and execute previous handler.

In the land of tag soup it's hard to decide which workaround is the correct one but it's definitively a bug that could explain your symptoms.

answered Nov 21, 2015 at 20:23
Sign up to request clarification or add additional context in comments.

1 Comment

Assuming jQuery is just using addEventListener (which, from memory, they are), per-spec they should fire the event such that all listeners are called. Therefore, the Chrome behaviour is wrong.
0
function load() {
 //do stuff
}

and the appropriate

<body onload="load()"> </body>
answered Nov 21, 2015 at 20:07

1 Comment

He's already using jQuery. It doesn't make much sense to get back to 1997 and inline even handlers ;-)
0

This runs fine in me. I even tried to create a dummy page with this snippet but could not replicate it.Here is snippet.Since the snippet you shared does not contain jquery , i opt to use same code .

 <!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>

Also note that there is a importance of semicolon after a function. Here are couple of snapshots Alerting on load

Alerting after 1 sec

answered Dec 5, 2015 at 6:33

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.