Console.log in IE8

喜欢而已 提交于 2019-12-08 07:26:37

问题


I have below piece of code, which, when tested, does not work in IE8. I have it running on IE11 and Chrome and it runs perfectly. I have debugged the code in IE8 which points at "console.log as a problem area. The most interesting thing is that when I start debugging JS in IE8 - it kicks it and this piece of code start working. Then again, on leaving debugging, closing and re-opening file - same story until you get into debugging))).

jQuery(function () {
    $('.Response input[type=radio]').change(function () {
        console.log(this.value)
        if (this.value == 'Y' || this.value == 'NA' || this.value == 'NS') {
            $(this).closest('.ui-accordion-content').prev().css("background", "#AADDB2"); 
        } else if (this.value == 'N') {
            $(this).closest('.ui-accordion-content').prev().css("background", "#FFC5C5"); 
        }
    });
});

Any ideas? Would appreciate yr help. PS. Unfortunately, user kind of "must" use IE8 and upgrading is not an option(((. Thank you in advance)))


回答1:


you can prevent ie8 errors on console.log with

if (!window.console){ console = {log: function() {}} };



回答2:


You can add some safety code to define console if it doesn't exist:

if (typeof console === "undefined" || typeof console.log === "undefined") {
    console.log = function(log_message) {
        alert(log_message);
    };
}


来源:https://stackoverflow.com/questions/22103156/console-log-in-ie8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!