0

I want to read a value of DOM element. I am new to browser extensions. I came across codes which provided help in executing a code in browser context but how do I fetch a value and use in extension's context?

var value = document.getElementById('id1'); // Here document should be of browser context.
Opal
  • 81,889
  • 28
  • 189
  • 210
Saba
  • 3,418
  • 2
  • 21
  • 34
  • Probably duplicate with this one: http://stackoverflow.com/questions/19758028/chrome-extension-get-dom-content – Dayton Wang Jun 15 '15 at 18:36
  • Your code can get the DOM element and use it in the extension's context. Since it's not working, something else isn't quite right. Since you've given us nothing else to go on, we can't do anything. – Teepeemm Jul 16 '15 at 17:46

2 Answers2

1

If you are looking to get the currently active tab, you would do this: https://developer.chrome.com/extensions/activeTab

How this will work will depend on whether you are in browser context, content scripts or background though.

I highly recommend reading the chrome extension guides: https://developer.chrome.com/extensions/getstarted. They help quite a bit, and the different scopes of the chrome extension are crucial to understand to successfully develop on it.

Brian
  • 1,513
  • 2
  • 14
  • 17
1

Try

var value = document.getElementById('id1').value;

// note the extra .value.

You have to access the DOM from content scripts.

Will White
  • 133
  • 1
  • 9