Passing an arbritrary JavaScript object in Xul
Posted
by
Tom Brito
on Stack Overflow
See other posts from Stack Overflow
or by Tom Brito
Published on 2011-01-04T13:11:13Z
Indexed on
2011/01/04
17:54 UTC
Read the original article
Hit count: 185
JavaScript
|xul
I'm following this example to pass an object to a window, but when it as an argument it's with "undefined" value.
This is my first window (obs. dump is the way to print to console when debug options are turned on):
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://XulWindowArgTest/locale/XulWindowArgTest.dtd">
<window id="windowID" width="400" height="300"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script>
<![CDATA[
function onClickMe(event) {
dump("begin\n");
try {
var args = {
param1: true,
param2: 42
};
args.wrappedJSObject = args;
var watcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher);
watcher.openWindow(null, "chrome://XulWindowArgTest/content/about.xul", "windowName", "chrome", args);
} catch (e) {
dump("error: " + e + "\n");
}
dump("end\n");
}
]]>
</script>
<button label="Click me !" oncommand="onClickMe();" />
</window>
and my second window:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://XulWindowArgTest/locale/XulWindowArgTest.dtd">
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="onload()">
<script>
<![CDATA[
function onload() {
dump('arg = ' + window.arguments[0].wrappedJSObject + "\n");
}
]]>
</script>
<label value="test" />
</window>
when the second window loads, it calls the onload and prints:
arg = undefined
Any idea how to fix it?
© Stack Overflow or respective owner