Skip to content

a page that downloads itself

<html><head>
    <title>Self-Downloading Page</title>
</head>
<body>
    <textarea id="textArea" rows="10" cols="50">Try writing here then click the button.</textarea><br>
    <button onclick="downloadPage()">Download This Page</button>
    
    <script>
        function downloadPage() {
            document.getElementById('textArea').textContent = document.getElementById('textArea').value;
            const html = document.documentElement.outerHTML;
            console.log(html);
            const blob = new Blob([html], { type: 'text/html' });
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = new Date().toISOString() + '.html';
            a.click();
            URL.revokeObjectURL(url);
        }
    </script>
</body></html>
Published inenglish

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *