Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we insert javascript into any webpage loaded in the browser

Tags:

javascript

I am looking into methods to inject javascript into any webpage loaded in the browser, so that I can traverse through the page's DOM. I use JQUERY for my scripting needs. Method should work in all browsers.

I tried using IFRAME and adding some html into it, but I cant. Please suggest some ways.

like image 899
pokrate Avatar asked Mar 31 '10 07:03

pokrate


People also ask

How can JavaScript be added to a website page?

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.

Can JavaScript run on browser?

To execute JavaScript in a browser you have two options — either put it inside a script element anywhere inside an HTML document, or put it inside an external JavaScript file (with a . js extension) and then reference that file inside the HTML document using an empty script element with a src attribute.

Can you use JavaScript on websites?

JavaScript is a more complicated language than HTML or CSS, and it wasn't released in beta form until 1995. Nowadays, JavaScript is supported by all modern web browsers and is used on almost every site on the web for more powerful and complex functionality.

Where do you put JavaScript code in browser?

To write a JavaScript, you need a web browser and either a text editor or an HTML editor. Once you have the software in place, you can begin writing JavaScript code. To add JavaScript code to an HTML file, create or open an HTML file with your text/HTML editor.


2 Answers

Try using Greasemonkey: http://www.greasespot.net/. You can use it to execute custom scripts on page load for any website you want. You can find some basic tutorials here: http://wiki.greasespot.net/Tutorials.

like image 130
dutchflyboy Avatar answered Oct 23 '22 12:10

dutchflyboy


I suggest to create a page with two iframes one to navigate to the designated website and other to get DOM Objects. in the first one navigate to the site and then select its HTML and append it in the body of the second Iframe.

iframe2.contentWindow.document.body.innerHTML = iframe1.contentWindow.document.body.innerHTML

then traverse the DOM Objects inside the second Iframe with your custom functions

like image 25
Kronass Avatar answered Oct 23 '22 10:10

Kronass