[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 651
  • Last Modified:

Firefox Extension: Getting JavaScript Variable From Web Document

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?
0
headzoo
Asked:
headzoo
  • 2
  • 2
1 Solution
 
basicinstinctCommented:
try

window.content.my_message
0
 
headzooAuthor 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".
0
 
basicinstinctCommented:
sorry my good fellow...
try this:

window.content.wrappedJSObject.my_message
0
 
headzooAuthor Commented:
@basicinstinct
Fantastic! Worked like a charm.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now