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

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

问题描述

我在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 ver。 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()从事任何工作Firefox与firebug以外的浏览器。

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']; (javascript)在尝试执行 console.log()之前,或者如果您不介意修改核心文件,请删除上面的代码。

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中不起作用并抛出错误

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

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