【问题标题】:Generating HTML file using javascript and using correct MIME types like "text/html"使用 javascript 生成 HTML 文件并使用正确的 MIME 类型,如“text/html”
【发布时间】:2019-08-25 13:02:18
【问题描述】:

目前,我正在使用此代码创建一个文本文件:

                    var text = "this is the content";                    
                    var name = "myfilename.txt";
                    var type = "text/plain";
                    var a = document.getElementById("a");
                    a.style.display = "block";
                    var file = new Blob([text], {type: type});
                    a.href = URL.createObjectURL(file);
                    a.download = name;

现在,如果我想创建一个 HTML 文件,而不是创建一个 .txt 文件。我明白了,我需要更改“myfilename.html”。

“类型”值应该是什么?

【问题讨论】:

标签: javascript html file


【解决方案1】:
                var text = "this is the content";                    
                var name = "myfilename.txt";
                var type = "text/html";
                var a = document.getElementById("a");
                a.style.display = "block";
                var file = new Blob([text], {type: type});
                a.href = URL.createObjectURL(file);
                a.download = name;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    • 2011-09-22
    • 2014-07-15
    • 1970-01-01
    • 2018-09-12
    相关资源
    最近更新 更多