Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将网页字段的内容获取到Javascript变量[Firefox插件SDK]_Javascript_Jquery_Firefox Addon_Mozilla_Firefox Addon Sdk - Fatal编程技术网

将网页字段的内容获取到Javascript变量[Firefox插件SDK]

将网页字段的内容获取到Javascript变量[Firefox插件SDK],javascript,jquery,firefox-addon,mozilla,firefox-addon-sdk,Javascript,Jquery,Firefox Addon,Mozilla,Firefox Addon Sdk,我正在使用Firefox插件SDK开发Firefox Mozilla插件/扩展。 现在,当用户单击我的加载项按钮时,我想从显示的网站中获取字段值“user”。网页的表单如下所示: <form name="input" action="html_form_action.asp" method="get"> Username: <input type="text" name="user" id="user" value="name of the user"> <i

我正在使用Firefox插件SDK开发Firefox Mozilla插件/扩展。 现在,当用户单击我的加载项按钮时,我想从显示的网站中获取字段值“user”。网页的表单如下所示:

<form name="input" action="html_form_action.asp" method="get">
   Username: <input type="text" name="user" id="user" value="name of the user">
<input type="submit" value="Submit">
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form><input type="text" id="txt-field" value="this is the value"/></form>
</body>
</html> 

用户名:
因此,我需要在我的外接程序文本框中显示“用户名”的值,这是我在外接程序中创建的


但是我不知道如何将数据从网站传递到附加变量/SITE。

您需要使用内容脚本。假设您有如下html:

<form name="input" action="html_form_action.asp" method="get">
   Username: <input type="text" name="user" id="user" value="name of the user">
<input type="submit" value="Submit">
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form><input type="text" id="txt-field" value="this is the value"/></form>
</body>
</html> 
script.js:

self.port.on('fetch-value', function() {
  self.port.emit('val', document.querySelector('#txt-field').value);
});
这是一个非常简单的示例,旨在向您展示main.js和内容脚本的通信方式。有关更多信息,我强烈建议您阅读有关内容脚本的文档:


这正是我想要的。谢谢你,先生!