I have a JS script that works fine in all browsers.
But for everybody’s surprise, in I.E. it does not work at the first try.
If, after I load my page, I press F12 (open the i.e. debugger) and refresh my page,
it works fine! Just like the others browsers! But for this work, i have to press F12.
Does i.e.’s debugger do something when we open it?
I cant find a solution!
Thanks in advance.
When you don’t have the debugger open, IE considers there to be no such thing as console.log, and gives you errors for calling an undefined function. When you hit F12, then you get the console, and so console.log is no longer undefined.
You can workaround by putting this at the top of your code:
Rather than editing out console.log from your code, this will merely make the browser do nothing if the console doesn’t exist, by defining them as a ‘do nothing’ function if they are undefined.
If you’re looking to shrink down your js file size (particularly important for mobile usage), you will eventually want to remove verbose logging on your release version.