如果我通过JavaScript生成HTML文件,则HTML文件的类型是什么?

时间:2019-04-03 21:35:06

标签: javascript html file

当前,我正在使用以下代码创建文本文件:

                    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”。

“类型”值应该是什么?

1 个答案:

答案 0 :(得分:0)

                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;