HTML button to save div content using javascript

前端 未结 4 924
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-03 05:45

I need to save content of div using pure javascript. I just edited one fiddle but I can\'t make it works :(

jsfiddle

4条回答
  •  臣服心动
    2021-01-03 06:16

    In your jsfiddle Java Script is configured to onLoad, which is why download() is not being invoked. Change it to No-Wrap, then you will be able invoke download() on onClick of the button.

    update download() as

    function download(){
        var a = document.body.appendChild(
            document.createElement("a")
        );
        a.download = "export.html";
        a.href = "data:text/html," + document.getElementById("content").innerHTML;
         a.click();
    
    }

提交回复
热议问题