admin管理员组

文章数量:1420104

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.

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.

Share Improve this question asked May 16, 2012 at 14:27 user823527user823527 3,71217 gold badges69 silver badges111 bronze badges 5
  • 2 Can you post your code to give more context please? – Brian Geihsler Commented May 16, 2012 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 Commented May 16, 2012 at 14:30
  • IE9, for basic things, works very similarly to other browsers now. Check your headers : stackoverflow./questions/10305631/… – Denys Séguret Commented May 16, 2012 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 Commented May 16, 2012 at 14:32
  • I think you should be checking for a bug in your code. – tzerb Commented May 16, 2012 at 14:37
Add a ment  | 

2 Answers 2

Reset to default 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');
}

Use jQuery, e.g.

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

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

本文标签: javascriptNo onclick for buttondivimg with IE 9Stack Overflow