Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does JavaScript only work after opening developer tools in IE once?

IE9 Bug - JavaScript only works after opening developer tools once.

Our site offers free pdf downloads to users, and it has a simple "enter password to download" function. However, it doesn't work at all in Internet Explorer.

You can see for yourself in this example.

The download pass is "makeuseof". In any other browser, it works fine. In IE, both buttons do nothing.

The most curious thing I've found is that if you open and close the developer toolbar with F12, it all suddenly starts to work.

We've tried compatibility mode and such, nothing makes a difference.

How do I make this work in Internet Explorer?

like image 598
James Bruce Avatar asked Oct 12 '11 15:10

James Bruce


People also ask

How do I edit JavaScript in IE developer tools?

Our first experiment in the latest build allows you to edit any JavaScript file in the debugger source viewer. Enable the “Edit JavaScript” toggle and restart your browser. Once the feature is enabled, simply click on the Debugger's source viewer to place the cursor and start modifying your JavaScript!

How do I open developer tools in Internet Explorer 11?

Pressing F12 or Ctrl + Shift + I opens a blank instance of the Microsoft Edge DevTools and displays the following message: Developer Tools aren't available in Internet Explorer mode. To debug the page, open it in Internet Explorer 11.


1 Answers

It sounds like you might have some debugging code in your javascript.

The experience you're describing is typical of code which contain console.log() or any of the other console functionality.

The console object is only activated when the Dev Toolbar is opened. Prior to that, calling the console object will result in it being reported as undefined. After the toolbar has been opened, the console will exist (even if the toolbar is subsequently closed), so your console calls will then work.

There are a few solutions to this:

The most obvious one is to go through your code removing references to console. You shouldn't be leaving stuff like that in production code anyway.

If you want to keep the console references, you could wrap them in an if() statement, or some other conditional which checks whether the console object exists before trying to call it.

like image 84
Spudley Avatar answered Sep 27 '22 16:09

Spudley