English 中文(简体)
console.log在使用时没有工作
原标题:console.log is not working when used in a Firefox, Greasemonkey script

我的使用者用<代码>console.log()印刷了一些信息。

该公司在Khat,但当我安装了这一用户文字时(Greasemonkey),网络组没有显示任何东西。

我寻求解决办法,有些人建议使用<代码>unsafeWindow,但也没有显示任何产出。 此外,不能将“unsafeWindow用于hr。 我甚至安装了大火,但没有使用。 我如何解决这一问题?

例如,我曾在第纳尔多尝试过这一用户文字:

// ==UserScript==
// @name        console
// ==UserScript==
console.log("hello");
最佳回答

You mean it doesn t work when installed via Greasemonkey, right?
Not long ago, Greasemonkey broke console.log (New! Bug report). Now, to see the results of a plain console.log() call from a Greasemonkey, you need to look in Firefox s Error console, not Firebug s.

您可通过以下紧迫方式看到FF s Error console:Ctrl

<>However,可在 Chrome和Greasemonkey的书写中使用unsafeWindow.console.log(。 Chrome现在对<代码>unsafeWindow的支持有限。

如果你使用<条码>unsafeWindow,你可以查阅。 Grasemonkey的“火力”伐木功能。 (Firebug必须安装,他们可能仍然不能在 Chrome印中工作;我已经用这种方式进行了测试。)


In Firefox, if Firebug is not installed, or it is not active for the page, then unsafeWindow.console.log() calls will display to the New "Web Console" (CtrlShiftK).
You need to use the unsafeWindow when inside a Greasemonkey script.

请注意:console.log(,console.info(,console.warn()和console.error( 本土——无需进行消防。

问题回答

Wait a minute: if the question is about logging in the console with Greasemonkey (I could swear I saw the tag ), why not use the GM_log method?

// ==UserScript==
// @name          GM_log Example
// @namespace     http://www.example.com/
// ==/UserScript==

GM_log("This is an example of GM_log");

还是我失踪了吗?

PS:你还可以检查<代码>javascript.options.showInConsole in about:config. 应为<代码>true。

I found that (testing with Chrome/Tampermonkey) you need:

window.log("<message goes here>");, not unsafeWindow.console.log("<msg>");, as unsafeWindow and console come up as undefined.

令我感到担忧的是,由于我很有理由相信,你在后来的浏览器中应当如何做。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jQuery block moving

I wanna move a div block to the top, so I coded like this: CSS part: .movingPart{ margin-top:80px; } jQuery part: $(document).ready(function() { $( #btn ).click(function() { $( .movingPart )....

Private FireFox plugin

I m looking at getting a FireFox plugin developed - but is it possible to create a plugin that is for private use only, so only those I share it with have it and not open to the masses? Need this for ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Cross-browser development

I m developing a web application for a new service, starting from Firefox 3.5. The interface design is tableless, only using divs + CSS & performance-blessed practices. Now, while being ...

Cross browser way of setting IFrame to "about:blank"?

Does anybody know a proper, cross-browser way to "empty" an IFrame? Is "about:blank" recognized without error across all browsers? Is it valid to give an IFrame an empty src?

热门标签