|
|
(11 intermediate revisions by 4 users not shown) |
Line 1: |
Line 1: |
| {{extdev}}
| | See [https://developer.mozilla.org/en/Error_Console Error Console] at developer.mozilla.org. |
|
| |
|
| You can print information to JavaScript Console using the following method:
| | [[Category:Redirects]] |
| | |
| <ol>
| |
| <li>Declare a variable (global if you're scripting your own window or [[Dev : Javascript coding guidelines|your object's member]] if you're overlaying an existing window):
| |
| <pre>var gConsoleService = Components.classes['@mozilla.org/consoleservice;1']
| |
| .getService(Components.interfaces.nsIConsoleService);</pre>
| |
| (note, that you can use <tt>toJavaScriptConsole()</tt> function to open JavaScript console on startup)
| |
| </li>
| |
| | |
| <li>Define a function:
| |
| <pre>function myExt_logMessage(aMessage) {
| |
| gConsoleService.logStringMessage('My extension: ' + aMessage);
| |
| }</pre>
| |
| | |
| </li>
| |
| <li>Use it like here:
| |
| <pre>myExt_logMessage("Initialized.");</pre>
| |
| </li>
| |
| </ol>
| |
| | |
| See also: [[Viewing dump() output]], [http://www.mozilla.org/projects/xpcom/using-consoleservice.html Using Console service].
| |
| | |
| [[Category:Development]] [[Category:Example code|Printing to Javascript Console]]
| |
Latest revision as of 20:54, 30 April 2009