Reputation: 9077
I'd like to write an extension that adds a div element to a page when a specific URL is loaded (e.g. when the url is http://www....&q=car&aq I'd like to have a div element containing "car" added to the webpage)
I'm already using addEventListener to check if a tab is open but I don't know how to do it for a specific URL.
p.s I'm not asking you guys to do my homework, only some links to tutorials speaking of this kind of tricks or basic examples d.s
Upvotes: 0
Views: 253
Reputation: 57691
It would probably be easier for you to create a user script for GreaseMonkey. There is tons of documentation (e.g. in the GreaseMonkey wiki) and also lots of existing user scripts to look at on userscripts.org. A script can be "compiled" into a regular extension (see User Script Compiler).
If you want to stick with a real extension then you probably want to register a progress listener. This way you will know when the location of a tab changes:
onLocationChange: function(aBrowser, webProgress, request, location)
{
if (location.host == "example.com")
doSomething(aBrowser.contentDocument);
}
Upvotes: 1
Reputation: 8542
You can get the url using the command window.location
so you can do something like
if (window.location.indexof("http://www.yoururl.com") != -1 && !$.browser.msie)
{
//add a div to the dom here.
}
This line !$.browser.msie is actually jquery, and might not compile incase you are not including jquery libraries, it basically checks for the browser version is not IE.
You can remove this part -- && !$.browser.msie -- if you are not using jquery.
Upvotes: 1