首页 » 收集 » 正文内容
JS保存内容到JSON和TXT文件
寻梦xunm| 325| 收集
1年前
超过659天 温馨提示
本文最后更新于2022年11月30日,已超过659天没有更新,若内容或图片失效,请留言反馈。

JS保存内容到JSON和TXT文件

downloadJsonOrTxt('demo.json', JSON.stringify({a:"b"}))    
<script>
    function downloadJsonOrTxt(filename, text) {
        var pom = document.createElement('a');
        pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
        pom.setAttribute('download', filename);
        if (document.createEvent) {
            var event = document.createEvent('MouseEvents');
            event.initEvent('click', true, true);
            pom.dispatchEvent(event);
        } else {
            pom.click();
        }
    }
</script>

文章来源于:https://yuefoo.com/236.html

0 赞 or 打赏
喜欢就打赏一点
微信 支付宝
隐私
Q Q:1340326824
邮箱:vipshiyi@qq.com
QQ群:422720328

我的音乐

微博客-专为自己编写开发的源码