View Source for XUL Applications

This article needs a technical review. How you can help.

Importing gViewSourceUtils

XUL applications wanting to show the source code for documents should import the viewSourceUtils.js script instead of attempting to open the viewSource.xul window themselves:

<script type="application/javascript" src="chrome://global/content/viewSourceUtils.js"/>

viewSourceUtils.js exposes a gViewSourceUtils global into the scope of the window that imports that script.

Method overview

gViewSourceUtils exposes several methods, but the only one you should be using directly is the viewSource method. The rest of those methods should be considered private, and might become inaccessible in the future.

void viewSource(aObject);

Methods

viewSource

Opens a viewer to the source code for some document or URI.

Parameters

The viewSource method takes an Object as its first and only parameter. The Object can include the following properties:

URL (required)
A string URL for the document to view the source of.
browser (optional)
The browser containing the document that we would like to view the source of. This is optional if outerWindowID is not passed.
outerWindowID (optional)
The outerWindowID of the content window containing the document that we want to view the source of. Pass this if you want to attempt to load the document source out of the network cache.
lineNumber (optional)
The line number to focus on once the source has loaded.

Deprecated API

This API is likely to go away in the future, and should no longer be used.

 The viewSource method will also accept the following arguments in place of the Object:

aURL
A string URL for the document to view the source of.
aPageDescriptor (optional)
A "descriptor" that allows the source to be retrieved from the network cache. This is usually gotten from the nsIWebPageDescriptor interface via currentDescriptor.
aDocument (optional)
The content document that we're attempting to load the source from.
aLineNumber (optional)
The line number to focus on once the source has loaded.

Document Tags and Contributors

 Contributors to this page: rolfedh, mconley
 Last updated by: rolfedh,