Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I capture and save the current state of a webpage using javascript

I need to get the entire contents of a page with javascript and send it to a server script to save it. I want to do this after the user has made some changes to the page using AJAX and other javascript tools. I don't want the state of certain elements. I'd like to essentially get everything inside the body tag so I can pass it to a server-side script. I have tried getelementbyid etc. but it seems to put the page in a loop and crashes.

Thanks

like image 455
Dogbot Avatar asked Oct 24 '10 04:10

Dogbot


People also ask

How do I save a website in current state?

Any web browser can quickly save the webpage that you are currently visiting. You will then be able to open this webpage at any time, even if you're offline. Press Ctrl + S (PC) or ⌘ Cmd + S (Mac). This opens the Save Page window in all major web browsers.

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.

How do I save a Web page?

Android. Save a web page on the Android app by opening the three-dot menu icon and tapping the download icon up top. A banner at the bottom of the screen will tell you when the page has been made available for offline reading. Click Open to view a static version of the page.


1 Answers

Try the following code:

var body = document.getElementsByTagName("body");
var bodycontent = body[0];

Then use "bodycontent.innerHTML" to retrieve the contents of it. If I'm not mistaken, it should provide the body's current content, after any javascript modifications that have been made to it.

like image 92
Doktor J Avatar answered Oct 20 '22 01:10

Doktor J