I want the source code of an HTML page ( 1.html ) to be used on another page ( 2.html ). In addition, I want to perform operations on it in 2.html .
1.html
2.html
Is there any way to do this?
EDIT: 1.html is a separate open webpage and I do not have access to change the source code. I have to do everything that I need, only using 2.html .
To convert the DOM 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?
Its very simple
In 2.html use this jQuery snippet
$.get("1.html", function(response) { alert(response) //do you operations });
JQuery
$.get('ajax/test.html', function(data) { $('.result').html(data); alert('Load was performed.'); });
I do not understand that you mean that you have to make changes, but you can just load the second page through AJAX
var url ="1.html"; $.ajax({ url: url, dataType: 'html' success: function(data){ //do something with data, which is the page 1.html } });
Usage can use the .html method to get all the html data of the page.
$(function(){ var a = ($('html').html()) })β