I'd like to change the content of webpages to put an element that changes according to the webpage.
e.g. I'd like to display a div element with the text "You are on http://www.google.com" when a user is on the website http://www.google.com but when a user goes to http://www.yahoo.com the div should change and display "You're on http://www.yahoo.com".
What I'm looking for is some kind of example to begin with (I hope not being the first person to think of this kind of trick).
There are a number of ways to dynamically manipulate HTML contents with Javascript: Directly change the contents with innerHTML and outerHTML. Create new HTML elements and insert them. Load and insert HTML contents with AJAX. Load data with AJAX, and generate a table or list. Dynamically load CSS files.
There are a number of ways to dynamically manipulate HTML contents with Javascript: Directly change the contents with innerHTML and outerHTML. Create new HTML elements and insert them. Load and insert HTML contents with AJAX.
1 innerHTML Method 2 HTML Code. We can change the contents of an HTML element such as an <p> tag or a <h> tag or any HTML element by using the innerHTML method. 3 Javascript Code. Now what Javascript code can go to this <p> tag with an id of para and change the contents to the content with Mars Rover. 4 Changing a Header Tag. ...
Here is the HTML code for the same: Changing font family with HTML <FONT> tag is static and permanent which may distract the users between the important and normal content. The other way is to dynamically change the font family of a content to be highlighted in a webpage whenever the visitor moves the mouse over it.
Here is one way to get something on the page, to show the current URL. This is not the proper approach, but it will give some visible change to start with.
These steps will start with the hello world example mentioned above, and modify it to inject some text on the web page.
get original files
insert new code
The menu item Tools | Hello World! | Hello World! will trigger this method:
XULSchoolChrome.BrowserOverlay = { /** * Says 'Hello' to the user. */ sayHello : function(aEvent) { // code starts here.
Add this code to he "sayHello" function
sayHello : function(aEvent) { try { // gBrowser is a global value var document = gBrowser.contentDocument;var doc_bodies = document.getElementsByTagName('body'); var doc_body = doc_bodies[0]; var first_element = doc_body.firstChild; var url_div = gBrowser.contentDocument.createElement('div'); url_div.id = 'added-by-firefox-extension'; url_div.innerHTML = document.URL; // add the url at the top of the document body doc_body.insertBefore( url_div, first_element ); // add the url at the end of the document body doc_body.appendChild( url_div ); } catch(e) { alert(e); }
compress the contents of showUrl
For me, the main pain point was figuring out how to use gBrowser to get at the web page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With