JavaScript console log in Magento

后端 未结 9 1508
长发绾君心
长发绾君心 2020-12-09 11:46

I have a custom phtml pages in Magento. As far I know Magento uses jQuery and prototype libraries.

For example, if I need external jQuery/jQueryUI, I need t

相关标签:
9条回答
  • 2020-12-09 11:56

    Using console.log() on browsers using Firebug 1.9.0+ with Magento up to 1.6.2.0 will fail, because Magento checks for the console.firebug property, but this property has been removed with Firebug 1.9.0 for privacy reasons.

    See the file js/varien/js.js:

    if (!("console" in window) || !("firebug" in console))
    {
        // :
    }
    

    Since Magento 1.7.0.0 this whole condition is commented out to fix this (and other) issue(s).

    0 讨论(0)
  • 2020-12-09 12:02

    So in light of not wanting to smear this site with profanity I will just say someone wasn't thinking in the magento team or somehow some crappy code got into live releases....

    If your console.log() is not working on a Magento installation it is likely because of the following:

    In magento/js/varien/js.js @ line ~636, Magento ver. 1.6.2.0

    if (!("console" in window) || !("firebug" in console))
    {
        var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
        "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
    
        window.console = {};
        for (var i = 0; i < names.length; ++i)
            window.console[names[i]] = function() {}
    }
    

    This effectively prevents console.log() from working in any browser other than firefox with firebug.

    To protect IE, surely, but I think this is the wrong way to get arround it, instead people should be aware of what they do with their logging and face the consequences when they don't.

    To fix it just make sure you put delete window['console']; (javascript) before you try to do a console.log(), or if you don't mind modifying the core files, delete the code above.

    Please note: remove the console fix for production, the delete doesn't work in IE6-8 and throws an error

    0 讨论(0)
  • 2020-12-09 12:11

    This is no longer an issue as of latest version in the Mage core. The code that breaks console.log() is commented out now. I'm not sure exactly in which version it was fixed, but it's fixed as of CE 1.7.0.2.

    0 讨论(0)
提交回复
热议问题