Alex Bogias
Alex Bogias

Reputation: 1880

Get value of an input element on a firefox addon

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">

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 :(

Upvotes: 0

Views: 867

Answers (1)

therealjeffg
therealjeffg

Reputation: 5830

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:

https://addons.mozilla.org/en-US/developers/docs/sdk/1.0/dev-guide/addon-development/web-content.html#content_script_events

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.

Upvotes: 1

Related Questions