JavaScript Javascript (strict) errors in Safari and Firefox with jQuery

I guess you know that browser don't support web functionalities the same way. We know that google always focalize their web library and their support firstly for chrome browser.

When you just have this error:

functions can only be declared at top level or immediately within another function

You must not put a function declaration inside any other block, like an if-statement or for-loop; cause any block scope that use curly braces: try-catch-finally, if-else if-else, for, switch, and ES6 also define new feature that utilize block scope such as class.

you can't: "use strict" { Function bar(){/****/} }

Therefore, independents solutions that i can provide are:

  • Find if there is a version of script (here google script or JQuery) (which is recent) where this problem have been solved.
  • You can also comment "use strict" in the corresponding script (for example in google script).
  • Make show that you first include google script and JQuery before the other js scripts.
  • Try to use non minified script library because something (an example which append with JQuery 1.11) it's the cause of the problem.

Before trying previous solutions, maybe this modified code can work:

<script type="text/javascript">

var trySubmission = function() {
 $(this).val("Submitting...");
 //check for required fields
 var emptyFields = $('[required]').filter(function() {
   $(this).removeClass("warning");
   if ($(this).val().length === 0){
     $(this).addClass("warning")
     return true
   } else {
     return false
   }
 });

 if (emptyFields.length === 0) {
   $(this).prop('disabled', true);
   document.getElementById('incompleteWarning').style.display = 'none';
   document.getElementById('bePatient').style.display = 'inline';
   google.script.run.withSuccessHandler(fileUploaded).uploadFiles(this.parentNode);
 } else{
  $(this).val("Submit Application")
  document.getElementById('incompleteWarning').style.display = 'inline';
  document.getElementById('incompleteWarning').style.color = 'red';
 } ;
}

$('#submitbutton').on('click', trySubmission ) ;

</script>
Answer:1

I have an action creator which does an expensive calculation and dispatches an action every time the user inputs something (basically real time updating). However, if the user inputs multiple things, ...

I have an action creator which does an expensive calculation and dispatches an action every time the user inputs something (basically real time updating). However, if the user inputs multiple things, ...

How could I create Pyramide of Stars that increase every row by 2 like that: * * * * * * * * * * * * * * * * My currently code: for (var x = 0; x < 5; x++) { for (var y = 0; y <= x; y = y ...

How could I create Pyramide of Stars that increase every row by 2 like that: * * * * * * * * * * * * * * * * My currently code: for (var x = 0; x < 5; x++) { for (var y = 0; y <= x; y = y ...

This is driving me absolutely insane, and I just cannot see what I have done wrong. Please help before I start bibbling and gnawing my colleagues leg off. He doesn't deserve that. I have an object I ...

This is driving me absolutely insane, and I just cannot see what I have done wrong. Please help before I start bibbling and gnawing my colleagues leg off. He doesn't deserve that. I have an object I ...

I currently have a table and each cell has a button. Upon clicking the button, based on that particular day (Monday or Tuesday), class (class 1 or class 2), and name (Kev or Josh), how can I push an ...

I currently have a table and each cell has a button. Upon clicking the button, based on that particular day (Monday or Tuesday), class (class 1 or class 2), and name (Kev or Josh), how can I push an ...