i want to add a button to download my html source code of a web page, i was able to do it but the problem is when i add a localhost url it works but when i add live url it open's the url instead of downloading it. so far i tried this
<a download href="http://localhost/test-new/">Download Source Code</a>
i also tried this
<button onclick="clicker()">Click me</button>
<script type="text/javascript">
function clicker() {
var anchorTag = document.createElement('a');
anchorTag.href = "http://localhost/test-new/";
anchorTag.download = "download";
anchorTag.click();
var element = document.getElementById('divContainer');
element.appendChild(anchorTag);
}
</script>
both of this working in localhost but not for live url. please help me