Skip to content

Instantly share code, notes, and snippets.

@mePy2
Created February 18, 2018 17:18
Show Gist options
  • Save mePy2/635992b19dcf05c7e48735cdf397c690 to your computer and use it in GitHub Desktop.
Save mePy2/635992b19dcf05c7e48735cdf397c690 to your computer and use it in GitHub Desktop.
Download the inner content of the <div class="default">, if present.
<script>
function downloadHTML() {
var divDef = document.querySelector(&quot;div.default&quot;).innerHTML;
var title = &quot;<data:post.title/>&quot; + &quot;.html&quot;;
if (divDef) {
var pom = document.createElement(&#39;a&#39;);
pom.setAttribute(&#39;href&#39;, &#39;data:text/html;charset=utf-8,&#39; + encodeURIComponent(divDef));
pom.setAttribute(&#39;download&#39;, title);
if (document.createEvent) {
var event = document.createEvent(&#39;MouseEvents&#39;);
event.initEvent(&#39;click&#39;, true, true);
pom.dispatchEvent(event);
} else {
pom.click();
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment