Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"save" current page state using javascript

Tags:

javascript

uri

What I'm trying to do is have a function create a uri anchor to redraw/rerender/(call it what you want) the entire page

Basically I want to be able to convert any page into a URI scheme so that when I navigate to such a link I get the entire page as is, kinda like saving a webpage. For example if I were to be editing a page and wanted to resume later with all the textareas just the way they are and the forms filled out, or if I wanted to save someones (small) page without having to worry that his site will go down and without having to save files on my computer (I want to use bookmarklets)

Here's what I have so far:

html = '<html>' + document.documentElement.innerHTML + '</html>';
//html = html.replace(/"/g, '\\"');
a = document.createElement('a');
a.href = 'data:text/html;charset=utf-8,' + html;
a.innerHTML = 'click here';
document.body.appendChild(a);

You see what I'm trying to do. Ok now the hard part is somehow using a regex to replace all double quotes that are already in double quotes but not ones that aren't.

For example if we create the page

<html><body>Testing</body></html>

and run the function enough times we're gonna get some issues with the 3rd and on links.

See what I mean: http://jsfiddle.net/AvSh3/3/

like image 343
qwertymk Avatar asked Dec 19 '10 02:12

qwertymk


People also ask

Does localStorage persist after refresh?

The main features of localStorage are: Shared between all tabs and windows from the same origin. The data does not expire. It remains after the browser restart and even OS reboot.


1 Answers

Use the built-in escape() function:

html = escape(html);
like image 137
Chris Dolan Avatar answered Nov 15 '22 04:11

Chris Dolan