2
edits
m (→Load Listener) |
|||
| Line 3: | Line 3: | ||
Each snippet normally includes some code to run at initialization. These are best run using a load listener. These snippets assume they are run in the context of a browser window. | Each snippet normally includes some code to run at initialization. These are best run using a load listener. These snippets assume they are run in the context of a browser window. | ||
== Load Listener == | == Load Listener ==You can't usually just run UI code as global code in your JavaScript. You need to wait for the XUL window to finish loading before trying to access any XUL elements.<pre>window.addEventListener("load", startup, true);function startup() { // access UI elements here}</pre>== Access the Browser ==Fennec has several JavaScript objects you should use to access the browser and the browser UI. The main objects are <code>Browser</code> and <code>Tab</code>. They have the following APIs:<pre>Browser------- property browsers gets an array of all XUL browsers. property selectedBrowser gets the currently active XUL browser. function getTabAtIndex(index) returns Tab or null. function getTabFromContent(content) returns Tab or null. function addTab(uri, bringFront) creates a new Tab with the given URI. returns the new Tab. function closeTab(tab) closes the given Tab. property selectedTab sets/gets the selected Tab.Tab------ property browser gets the XUL browser for the Ta | ||
You can't usually just run UI code as global code in your JavaScript. You need to wait for the XUL window to finish loading before trying to access any XUL elements. | |||
<pre> | |||
window.addEventListener("load", startup, | |||
function startup() { | |||
} | |||
</pre> | |||
== Access the Browser ==Fennec has several JavaScript objects you should use to access the browser and the browser UI. The main objects are <code>Browser</code> and <code>Tab</code>. They have the following APIs:<pre>Browser------- property browsers gets an array of all XUL browsers. property selectedBrowser gets the currently active XUL browser. function getTabAtIndex(index) returns Tab or null. function getTabFromContent(content) returns Tab or null. function addTab(uri, bringFront) creates a new Tab with the given URI. returns the new Tab. function closeTab(tab) closes the given Tab. property selectedTab sets/gets the selected Tab.Tab------ property browser gets the XUL browser for the | |||
== Listening for Browser Events == | == Listening for Browser Events == | ||
edits