IE runs javascript only after pressing F12

2019-02-12 11:49发布

I have a strange problem in Internet Explorer with Javascript. In every browser i did the test the javascript is enabled, but it seems to run only after i pres the F12, running it in debug mode. And what is more confusing, after starting the IE debugger everything is working as suppose to. Any ideas what it could be ?

1条回答
【Aperson】
2楼-- · 2019-02-12 12:24

If you're calling:

console.log('...some text here...');

or any related method of console without having checked if window.console exists, the script will fail silently. Opening the console leads to window.console existing, which allows the script to continue execution.

Add "window.console && " before your calls to console:

window.console && console.log('works');
查看更多
登录 后发表回答