在Firefox插件上获取输入元素的值 [英] Get value of an input element on a firefox addon

查看:84
本文介绍了在Firefox插件上获取输入元素的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在main.js中获取此输入元素的值:

How i can fetch the value of this input element in my main.js:

<input type="hidden" value="12124054" id="ctl00_cphContent_hdnID" name="ctl00$cphContent$hdnID">

我尝试了var id = document.getElementById("ctl00_cphContent_hdnPlayerID").value;contentWindow.document.getElementById("ctl00_cphContent_hdnPlayerID").focus();,但是我收到了文档和contentWindows无法识别的错误:(

I tried var id = document.getElementById("ctl00_cphContent_hdnPlayerID").value; and contentWindow.document.getElementById("ctl00_cphContent_hdnPlayerID").focus(); but i am getting errors that document and contentWindows are unidentified :(

推荐答案

您需要使用内容脚本从页面获取值,然后将该值发送给main.js-这是因为Web内容固有地不受信任.插件SDK.有关如何使用内容脚本的更多信息,请参阅以下文档:

You need to get the value from the page using a content script and then send the value to main.js - this is because web content is inherently untrusted by the addon-sdk. Please see these docs for more on how to use content scripts:

这里是Builder上的一个示例附加组件,它显示了如何将内容脚本中的值传递回main.js.在这种情况下,我使用xui库更轻松地将事件绑定到pgae中.

Here is an example add-on on Builder that shows how to pass values frmo the content script back to main.js. In this case I'm using the xui library to more easily bind events in the pgae.

这篇关于在Firefox插件上获取输入元素的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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