Magento 中的 JavaScript 控制台登录 [英] JavaScript console log in Magento

查看:32
本文介绍了Magento 中的 JavaScript 控制台登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Magento 中有一个自定义的 phtml 页面.据我所知 Magento 使用 jQuery 和原型库.

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

例如,如果我需要外部的jQuery/jQueryUI,我需要使用.noConflict()

For example, if I need external jQuery/jQueryUI, I need to use .noConflict()

但是如果我想使用

console.log('Hello world');

在 Chrome 15 控制台中,我没有得到任何响应,什么也没有.也尝试使用 Firebug.

In Chrome 15 console I got no response, nothing. Also tried with Firebug.

显然与 Magento JavaScript 代码存在一些冲突.有什么解决办法吗?

Obviously there is some conflict with Magento JavaScript code. Is there any solution?

推荐答案

因此,鉴于不想用亵渎来抹黑这个网站,我只想说有人在 magento 团队中没有考虑过,或者不知何故一些糟糕的代码进入了现场发布....

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....

如果您的 console.log() 在 Magento 安装中无法正常工作,可能是因为以下原因:

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

magento/js/varien/js.js @ line ~636,Magento 版本.1.6.2.0

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() {}
}

这有效地防止了 console.log() 在带有 firebug 的 firefox 以外的任何浏览器中工作.

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

当然,为了保护 IE,但我认为这是绕过它的错误方法,相反,人们应该意识到他们对日志记录做了什么,并在他们不这样做时面对后果.

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.

要修复它,请确保在尝试执行 console.log() 之前放置 delete window['console']; (javascript),或者如果你不介意修改核心文件,删除上面的代码.

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.

请注意:删除控制台修复以进行生产,删除在 IE6-8 中不起作用并引发错误

这篇关于Magento 中的 JavaScript 控制台登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆