【问题标题】:Pass Parameter into a new window opened from .js file将参数传递到从 .js 文件打开的新窗口中
【发布时间】:2018-03-12 14:42:51
【问题描述】:

我打算从 .js 文件更新我网站上的文本框。假设我有一个网站http://abcd-support。我有一个要执行的 .js 文件。我想要做的是,执行我的 .js 文件,它将打开 http://abcd-support 并更新文本框的值。这是我的 .js 文件:

var newWindow = window.open('http://abcd-support');
newWindow.onload = function(){
    newWindow.document.getElementById('textbox').value = 'test';
};

新窗口已经打开,但是我的http://abcd-support 中的文本框(id 为'textbox')仍然是空白的。它应该填写“测试”。

以前有没有人遇到过同样的问题?

注意:我使用的是 .js 文件。不是 HTML 文件我使用的是 Google Chrome。

【问题讨论】:

标签: javascript google-chrome parameters window


【解决方案1】:

您需要创建一个 ID 为 textbox 的元素来为其赋值。

在这种情况下,我知道这是input text

var x = document.createElement("INPUT");
x.setAttribute("type", "text");
x.setAttribute("id", "textbox");

告诉我是否有帮助

【讨论】:

  • 文本框的 id 是“文本框”。它在我的 http://abcd-support
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多