Reputation: 1613
I am a beginner in developing Chrome extension I am having problem as below:
How can I execute a script for currently open page? I want to do it using background.html
. I already tried to run
document.addEventListener('DOMContentLoaded', exec_fun);
or
window.addEventListener('DOMContentLoaded', exec_fun);
and also registered backgroung.html
in manifest.json
to execute the exec_fun()
function, but it is not working. What am I doing wrong?
Upvotes: 0
Views: 191
Reputation: 3774
if you want a script to run on every page, you should write a content script: http://code.google.com/chrome/extensions/content_scripts.html
Content scripts run inside the page, so you can access its DOM and use its events.
On the other hand, background.html run only once on extension start up (usually when the browser opens), and it's independent from any tab or page. Its your extension "operations base". That's no the place where you want to put your script, except that you use a listener to catch every page change with onUpdated, that fires every time the tab's url change:
http://code.google.com/chrome/extensions/tabs.html#event-onUpdated
"and also registered backgroung.html in manifest.json to execute the exec_fun() function"
How are you trying to do that? I think that's no the way.
Upvotes: 1