本文介绍了[储存"使用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

基本上我希望能够将任何页面转换为URI方案,以便当我导航到这样的链接时,我得到整个页面,有点像保存网页。例如,如果我要编辑一个页面,并希望稍后恢复所有textareas就像他们的方式和表格填写,或者如果我想保存某些(小)页面而不必担心他的网站将去我无需在我的计算机上保存文件(我想使用bookmarklet)

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.

例如如果我们创建页面

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

并运行该功能足够多次我们将在第3和链接上遇到一些问题。

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

明白我的意思:

推荐答案

这在我自己的页面上测试时有效:

This works when testing on my own page:

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

我猜这只是一个jsBin / jsFiddle技术性但我不知道为什么。无论如何,如果人们想用这个来制作bookmarklet,那就是链接:

I'm guessing that it's just a jsBin/jsFiddle technicality but I have no clue why. Anyway if people want to use this to make bookmarklets heres the link:

....

嗯,我无法弄清楚如何在SO中制作书签链接,如果你只想用这个位置创建一个新的书签:

Well I can't figure out how to make a bookmarklet link in SO, if you want just create a new bookmark with this location:

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

无论如何,通过这个有趣的工具,我们可以在第一个链接中执行Jon所做的事情:

Anyway with this fun tool we can do things like Jon does in the first link here:

这篇关于[储存&QUOT;使用javascript的当前页面状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-25 02:49