简体   繁体   中英

Windows vista Internet Explorer 9 console.logs

I am having an issue with IE9 on vista. I had console.logs/errors/warns being used, but that seemed to break IE9 (found many articles of why) if I hadnt already opened the developer tools. so I applied the following to make console.log available to the ie9

window.console.log = function(){}
window.console.error = function(){}
window.console.warn = function(){}
window.console.info = function(){}
window.console.debug = function(){}

So that seemed to load past where it did before. I also have encountered an issue in the past where if you have a trailing comma on an object definition than IE would break aswell.

example:

a = {a:1, b:2, c:3,}

I am using CoffeesScript so I am assuming that this isnt an issue.

So my problem is that there seems to be a javascript method breaking internet explorer. But only when the developer tools hasnt been opened. But I cannot view the error without opening the developer tools.

Can I make my javascript errors available on windows vista IE9 without initialising the developer console

Thanks

window.console itself is not defined in IE when the debugger is not running so you need to add this first line for IE:

window.console = {};
window.console.log = function(){}
window.console.error = function(){}
window.console.warn = function(){}
window.console.info = function(){}
window.console.debug = function(){}

Personally, I'd suggest this which will take care of all browsers:

if (!window.console) {
    window.console = {};
    window.console.log = function(){}
    window.console.error = function(){}
    window.console.warn = function(){}
    window.console.info = function(){}
    window.console.debug = function(){}
}

If this doesn't help with the particular issue that's afflicting you, then you can try to install your own exception handlers around possible areas where the problem is and attempt to catch the exception yourself. You may have to put details about the exception onto the screen (append them to a visible div or put them in an alert) if you can't use the debugger.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM