Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get HTML source code as a string

I want the source code of an HTML page (1.html) to be used in another page (2.html). Furthermore, I want to perform operations on it in 2.html.

Is there a way to do this?

EDIT: 1.html is a separate public webpage and I do not have access to make changes to its source code. I have to do whatever I need only by using 2.html.

like image 278
user1196522 Avatar asked Feb 29 '12 10:02

user1196522


People also ask

How to get whole HTML in JavaScript?

If you want to find all HTML elements that match a specified CSS selector (id, class names, types, attributes, values of attributes, etc), use the querySelectorAll() method. This example returns a list of all <p> elements with class="intro" .

How do I extract the HTML code from a website?

Right-click a blank part of the web page and select Show Page Source from the pop-up menu that appears. Once the developer options are enabled, you can also press Command + option + U to view the source code.

How do I extract HTML from HTML file?

On Firefox, you can also use the keyboard shortcut Command-U to view the source code of a webpage. On Chrome, the process is very similar. Navigate to the top menu item “View” and click on “Developer/View Source.” You can also use the keyboard shortcut Option-Command-U .

What is an HTML string?

Unlike most HTML parsers which generate tree structures, HTMLString generates a string of characters each with its own set of tags. This flat structure makes it easy to manipulate ranges (for example - text selected by a user) as each character is independent and doesn't rely on a hierarchical tag structure.


1 Answers

To get the DOM converted to a string:

document.getElementsByTagName('html')[0].innerHTML

Question: what do you mean by "use it"? Do you need to include 1.html inside 2.html? Or do you just need to process it?

like image 137
Samuele Mattiuzzo Avatar answered Sep 24 '22 23:09

Samuele Mattiuzzo