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
2 Answers
Reset to default 6You 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
版权声明:本文标题:javascript - No onclick for button, div, img with IE 9 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745327268a2653650.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论