Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: Get current page CURRENT source

I have HTML and I need to get page source of this html.

document.documentElement.outerHTML

or

$.ajax({
async: true,
type: 'GET',
cache: false,
url: window.location.href,
success: function(data) {
   alert(data);
}
});

is working, but they display originally source. If I change html (by jQuery, for example), they don't read my changes.

Is it possible read CURRENT source of page?

like image 803
indapublic Avatar asked Dec 17 '12 12:12

indapublic


People also ask

How to get the current URL of the page in JavaScript?

If you're using JavaScript in the browser you can get the full current URL by using window. location. href .

How do I get the current page number in JavaScript?

var lighboxHeight = (pagenumber-1)*window.

Can JavaScript read the source of any Web page?

If for some odd reason, you wanted to view the source code of another page without having to actually browse to that page and click “page view source,” you can use JavaScript to do so. In the example below, I use the “window.

Which property returns the URL of the current page?

The window.location.href property returns the URL of the current page.


1 Answers

Tried it on chrome and it works. Use

document.documentElement.innerHTML

Funnily enough your code also worked

document.documentElement.outerHTML

Check out the html printed to the console in this fiddle. It actually contains the changes made by jQuery.

like image 112
Bruno Avatar answered Oct 01 '22 02:10

Bruno