問題描述
我在 Magento 中有一個(gè)自定義的 phtml 頁面.據(jù)我所知 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 控制臺(tái)中,我沒有得到任何響應(yīng),什么也沒有.也嘗試使用 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?
推薦答案
因此,鑒于不想用褻瀆來抹黑這個(gè)網(wǎng)站,我只想說有人在 magento 團(tuán)隊(duì)中沒有考慮過,或者不知何故一些糟糕的代碼進(jìn)入了現(xiàn)場發(fā)布....
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 安裝中無法正常工作,可能是因?yàn)橐韵略?
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.
當(dāng)然,為了保護(hù) IE,但我認(rèn)為這是繞過它的錯(cuò)誤方法,相反,人們應(yīng)該意識(shí)到他們對(duì)日志記錄做了什么,并在他們不這樣做時(shí)面對(duì)后果.
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.
要修復(fù)它,請(qǐng)確保在嘗試執(zhí)行 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.
請(qǐng)注意:刪除控制臺(tái)修復(fù)以進(jìn)行生產(chǎn),刪除在 IE6-8 中不起作用并引發(fā)錯(cuò)誤
這篇關(guān)于Magento 中的 JavaScript 控制臺(tái)登錄的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!