2

Does anyone know of a workaround for the bug in IE9 where a function in the onclick for these page elements: button, div, img, isn't called? So you click on the element and nothing happens. This came up on a page that I am developing. If I launch the F12 debugger, the problem goes away. But I cannot ask site visitors to click F12 to browse the page! What are the solutions to this? I thought that this might only happen when the element is created dynamically in javascript. But this also happens if the element is defined in the HTML.

user823527
  • 3,644
  • 17
  • 66
  • 110
  • 2
    Can you post your code to give more context please? – Brian Geihsler May 16 '12 at 14:29
  • have you tried binding the click event with jQuery? Maybe that could solve the problem and make it more IE safe. – Odinn May 16 '12 at 14:30
  • IE9, for basic things, works very similarly to other browsers now. Check your headers : http://stackoverflow.com/questions/10305631/ie9-float-with-overflowhidden-and-table-width-100-not-displaying-properly – Denys Séguret May 16 '12 at 14:31
  • I was wondering if anyone was aware of the problem and if there was an explanation for it. This is something that turned up recently and before changing all the buttons, images to bind the click event, I thought I'd ask. – user823527 May 16 '12 at 14:32
  • I *think* you should be checking for a bug in your code. – tzerb May 16 '12 at 14:37

2 Answers2

6

You mentioned that the code works if the user has the developer tools open, which means your problem is most likely that you are using console.log statements in your code.

in IE, printing to the console when the developer tools are not open will cause a javascript exception, which would cause your event handlers to stop working.

to get around this problem, wrap all of your console statements with an if statement:

if (console) {
    console.log('foo');
}
jbabey
  • 45,965
  • 12
  • 71
  • 94
  • That's excellent! There are many people out there in forums that are searching for an answer to that one. – user823527 May 16 '12 at 15:37
  • @user823527 one of the many joys of developing for internet explorer... [relevant](http://www.vexite.com/images/2011/06/browser-war-illustration.jpg) – jbabey May 16 '12 at 15:42
  • After some hours debugging I found such an `console.log` issue inside a sub routine called by the click handler. Thanks for that hint! – alex Nov 22 '12 at 15:38
  • Even better, we can build a cross-browser `console.log()`: http://patik.com/blog/complete-cross-browser-console-log/ – Raptor Apr 11 '16 at 10:51
0

Use jQuery, e.g.

$('#myButton').click(function() {
    // code goes here
});

This will work out the correct code to fire the click event.

CompanyDroneFromSector7G
  • 4,291
  • 13
  • 54
  • 97