We help IT Professionals succeed at work.

Firefox Extension: Getting JavaScript Variable From Web Document

headzoo
headzoo asked
on
680 Views
Last Modified: 2013-12-07
Hi all,
I'm trying to find out how to access a JavaScript variable in a web document, from within a Firefox extension. So if I open a document that looks like this:

<html>
<body>
<script type="text/javascript">
var my_message = 'Hello World!';
</script>
</body>
</html>

How can I get the value of my_message from my Firefox extension?
Comment
Watch Question

try

window.content.my_message

Author

Commented:
@basicinstinct
That doesn't seem to work. I'm using the function:

function Test_Function()
{
    alert(window.content.my_message);
}

That is rigged up to a button in a Firefox toolbar. I press the button after the page is fully loaded, and it just shows up as "undefined".
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
@basicinstinct
Fantastic! Worked like a charm.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.