使用 JavaScript 将变量值从子 XUL 窗口传递到父 XUL 窗口 [英] Pass variable values from child XUL window to parent XUL window using JavaScript

查看:27
本文介绍了使用 JavaScript 将变量值从子 XUL 窗口传递到父 XUL 窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数可以从 xul 文件(比如 tree.xul)中获取选中复选框的值.在另一个 XUL 文件中有一个文本框,我想在其中传递所选复选框的值(标签值)(比如 textbox.xul).

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).

最初我是从textbox.xul"文件打开我的tree.xul"文件.当我选择复选框值并单击按钮将值传递给另一个 xul 文件(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").

我在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();

window.close();

传递值后关闭窗口(tree.xul").

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?

我正在尝试使用 Mozilla 对话框中的解释,但它不起作用.

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;

} 

在这里,用户选择tree.xul"文件中的复选框,我有按钮(function get()") 将值添加到texbox.xul"窗口中的文本框.

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.

这是从 text-box.xul 文件中打开 tree.xul 的函数:

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);
}

请帮我将值传递给另一个 XUL 窗口中的文本框.

Please help me to pass the values to the text-box in another XUL window.

谢谢.

推荐答案

你可能想使用这样的东西:在 XUL 中向对话框传递额外的参数

You may want to use something like this: Passing extra parameters to the dialog in XUL

这提供了一种在 xul 文件之间传递值的简单方法.

This provides a simple way to pass values across xul files.

对于您的问题,您可以在 textbox.xul 中执行类似操作.这将打开 tree.xul 以及额外的参数 returnValues:

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);

注意 modal 是必须的.

Note modal is a must.

接下来在您的 tree.xul 中,存储您想要传递给 textbox.xul 的所有值(我们称之为 x),如下所示:

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

注意 window.argument[0] 指的是 returnValues

现在您可以在 textbox.xul 中访问 x 的值(在您的情况下是标签的名称),如下所示:

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;

基本上,

  1. 您在打开子窗口时将参数传递给它.

  1. 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.

这篇关于使用 JavaScript 将变量值从子 XUL 窗口传递到父 XUL 窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆