객체를 윈도우에 전달하려면 this example을 따르지 만, 인수로 "undefined"값이있는 객체는 전달합니다.Xul에서 임의의 JavaScript 객체 전달
<?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>
내 두 번째 창 :
<?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>
이 내 첫 번째 창입니다. (OBS 덤프는 debug options이 켜져 때 콘솔에 인쇄하는 방법입니다) 두 번째 창이로드되면 onload를 호출하여 다음을 인쇄합니다.
arg = 정의되지 않음
어떻게 수정해야합니까?
openDialog 접근법에 대해서는 페이지의 첫 번째 예제 인 'openDialog (null, "chrome : //XulWindowArgTest/content/about.xul", "windowName", "chrome", {status : "dump ('arg ='+ window.arguments [0] .maxProgress +"\ n ");'를 사용하여 읽지 만'undefined ' –
또한 고마워요. 불행히도 여전히 '정의되지 않은'상태입니다. 약속으로 질문을 업데이트했습니다. –
@Tom Brito, openDialog는 .open과 다른 매개 변수를 가지고 있으므로 해당 null 매개 변수를 제거해야합니다. 실제로는 해당 함수 호출이 실제로 작동합니다. 그 말로는, 내가 여기서 일하는 귀하의 질문에서 코드의 버전이 있습니다. 귀하의 버전이 정의되지 않은 이유에 대해 명확하지 않습니다. 사실, 전체 객체를 debug()에 보내고 있습니다. 어떻게 처리하는지 모르겠습니다. jsdump를 사용하면 객체라는 것을 알 수 있습니다. print window.argument [0] .wrappedJSObject.param2가 더 나은 선택 일 수 있습니다. – pc1oad1etter