2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

表示してるWEBページのHTMLソースをダウンロードするJavascript

Posted at

HTMLファイルのダウンロード

現在表示してるページのHTMLソースをHTMLファイルでダウンロードするスクリプトです。
スクリプトを実行すると即時、
既存のダウンロードフォルダにファイルがダウンロードされます。

Javascript原文

function getHTMLSource() {
    return document.documentElement.outerHTML;
}

function saveHTMLToFile(htmlContent) {
    var blob = new Blob([htmlContent], { type: 'text/html' });
    var downloadLink = document.createElement('a');
    downloadLink.href = window.URL.createObjectURL(blob);
    downloadLink.download = 'page_source.html';
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);
}

var htmlContent = getHTMLSource();

saveHTMLToFile(htmlContent);

ブックマークレット

javascript:(function(){function%20getHTMLSource(){return%20document.documentElement.outerHTML;}function%20saveHTMLToFile(htmlContent){var%20blob=new%20Blob([htmlContent],{type:'text/html'});var%20downloadLink=document.createElement('a');downloadLink.href=window.URL.createObjectURL(blob);downloadLink.download='page_source.html';document.body.appendChild(downloadLink);downloadLink.click();document.body.removeChild(downloadLink);}var%20htmlContent=getHTMLSource();saveHTMLToFile(htmlContent);})();

好きにカスタマイズして使ってください。
以上

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?