이 스크립트는 현재 URL을 파일에 저장하는 데 사용됩니다.
<script type="text/javascript">
setTimeout("create(window.location.href, 'file.html', 'text/plain')");
function create(text, name, type) {
var dlbtn = document.getElementById("save");
var file = new Blob([text], {type: type});
save.href = URL.createObjectURL(file);
save.download = name;
}
</script>
<a href="javascript:void(0)" id="save"><button>SAVE</button></a>
하지만 다음과 같이 완성 된 파일이 필요합니다.
<script type="text/javascript">
window.location.href = "CURRENT URL GOES HERE";
</script>
간단한 템플릿 리터럴을 사용하면 트릭이됩니다. setTimeout()
또한를 문자열 대신 콜백으로 변경하고 묵시적 0 대신 0 지연을 갖도록 변경 text/plain
했습니다 text/html
. 제가 변경 한 또 다른 것은 유형이에서 으로 변경되었습니다 .
<script type="text/javascript">
setTimeout(() => create('file.html', 'text/html'), 0); // type needs to be text/html to save as an HTML file and not a txt file
function create(name, type) {
var dlbtn = document.getElementById("save");
// Template literal
const text = `<script type="text/javascript">
window.location.href = "${window.location.href}";
</scri${"pt"}>` // Have to do the ${"pt"} to fix HTML wanting to close the script tag
var file = new Blob([text], {type: type});
dlbtn.href = URL.createObjectURL(file);
dlbtn.download = name;
}
</script>
<a href="javascript:void(0)" id="save"><button>SAVE</button></a>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다