34

HTMLページを操作した後、HTMLページの状態を保存できるようにしたいと考えています。

チェックボックスをクリックしたり、javascript がさまざまな要素の値を設定したりします。

「javascript-rendered」ページを保存するにはどうすればよいですか?

ありがとう。

4

4 に答える 4

44

Chrome (および明らかに Firefox) には、レンダリングされたコンテンツをクリップボードにコピーする特別な copy() メソッドがあります。次に、好みのテキスト エディターに貼り付けることで、必要なことを行うことができます。

https://developers.google.com/chrome-developer-tools/docs/commandline-api#copyobject

コンソールの例:

copy(document.body.innerHTML);

注: メソッドの実行後に Chrome が undefined を報告していることに気付きましたが、メソッドは正しく実行されているようで、正しいコンテンツがクリップボードに保存されています。

于 2013-11-16T21:05:21.463 に答える
27

That should do and will grab the ALL page not just the body

console.log(document.getElementsByTagName('html')[0].innerHTML);
于 2012-04-13T16:39:00.653 に答える
4

document.body.innerHTML will get you the HTML representation of the current document body.

That will not necessarily include all internal state of DOM objects because the HTML contains the initial default state of objects, not necessarily the state that they may have been changed to. The only way to guarantee you get all that state is to make a list of what state you want to save and actually programmatically get that state.

To answer the part of your question about saving it, you'll have to describe more about what problem you're really trying to solve.

于 2012-04-13T16:38:29.113 に答える