问题
I have a function to get the values of the selected check-box from the xul file(Lets say tree.xul). In another XUL file has the text-box where I want to pass the values(label values) of the selected check-box(Lets say textbox.xul).
Originally I'm opening my "tree.xul" file from "textbox.xul" file. When I select the check box values and click on the button to pass the values to an another xul file("textbox.xul").
I have a text-box in "textbox.xul" file, I want to pass the values of the check-box to this text-box.
<textbox id="ali" value=""/>
<button label="Contacts" onclick="DisplayContacts();"/>
In my script I'm trying like this but it's not working and also I have included this small piece of code function
window.close();
to close the window("tree.xul") after passing the values.
Do i have to use an array to store all the values of the variable?
I'm trying using the explanation from Mozilla dialog but it's not working.
function get() { // check the alignment on a number of cells in a table.
var table = document.getElementById("box");
var cells = table.getElementsByTagName("checkbox");
for (var i = 0; i < cells.length; i++)
{
var cell = cells[i];
if(cell.checked) {
alert(cell.getAttribute("label"));
var x = cell.getAttribute("label");
x = window.arguments[0];
// or cell.label
}
}
window.close();
}
This is the code for the check-box values created dynamically:
function choose()
{
//alert('hi');
var tree = document.getElementById('myTodoListTree');
for (var i = 0; i < tree.view.rowCount; i++) {
if (tree.view.getCellValue(i, tree.columns.getColumnAt(0)) == 'true'){
var empty = " ";
var contact = (tree.view.getCellText(i, tree.columns.getNamedColumn("name"))+ empty+
tree.view.getCellText(i, tree.columns.getNamedColumn("lastname"))+ empty+ "Contacts:");
var ggmail = tree.view.getCellText(i, tree.columns.getNamedColumn("gmail"));
var yyahoo = tree.view.getCellText(i, tree.columns.getNamedColumn("yahoo"));
var existingEl = document.getElementById('box');
var capt = document.createElement('groupbox');
existingEl.appendChild(capt);
var captionEl = document.createElement('caption');
capt.appendChild(captionEl);
captionEl.setAttribute('label', contact );
captionEl.setAttribute('style', 'color: blue;');
var existing = document.getElementById('box');
var checkbox = document.createElement('checkbox');
capt.appendChild(checkbox);
checkbox.setAttribute('label', ggmail );
checkbox.setAttribute('style', 'color: green;');
var existing = document.getElementById('box');
var checkbox = document.createElement('checkbox');
capt.appendChild(checkbox);
checkbox.setAttribute('label', yyahoo);
checkbox.setAttribute('style', 'color: green;');
}
}
return arr;
}
Here the user select the check-box in the "tree.xul" file and I have button("function get()") to add the values to the text-box in the "texbox.xul" window.
This is the function to open the tree.xul from the text-box.xul file:
function DisplayContacts()
{
var returnValues = { out: null };
window.openDialog("chrome://hello/content/sundayevening2.xul","sundayevening2","", returnValues);
}
Please help me to pass the values to the text-box in another XUL window.
Thanking you.
回答1:
You may want to use something like this: Passing extra parameters to the dialog in XUL
This provides a simple way to pass values across xul files.
For your problem you can do something like this in the textbox.xul. This will open tree.xul along with the extra parameter returnValues:
var returnValues = { out: null };
window.openDialog("tree.xul", "tree", "modal", returnValues);
Note modal
is a must.
Next in your tree.xul, store all the values (lets call it x) that you want to pass to textbox.xul as below:
window.arguments[0].out = x
Note window.argument[0] refers to returnValues
Now you can access the values of x (which is the names of the labels in your case) in textbox.xul as follows:
var labels = returnValues.out;
Basically,
You pass a parameter to the child window at the time of opening it.
Then in the child window, fill the parameter with the values that wish to pass back to the parent window and then close the child window.
Now back in the parent window you can access the parameter that you passed to the child and it contains information updated by the child window.
来源:https://stackoverflow.com/questions/7172333/pass-variable-values-from-child-xul-window-to-parent-xul-window-using-javascrip