Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将textarea内的内容导出为不适用于Internet Explorer 11的Html_Javascript_Jquery_Html_Web_Web Applications - Fatal编程技术网

Javascript 将textarea内的内容导出为不适用于Internet Explorer 11的Html

Javascript 将textarea内的内容导出为不适用于Internet Explorer 11的Html,javascript,jquery,html,web,web-applications,Javascript,Jquery,Html,Web,Web Applications,将textarea内容导出为html文件的Javascript函数在Internet explorer 11上不起作用,但在其他浏览器上起作用。它从单选按钮值(如“Output.html”)中获取文件名。我正在附加Javascript函数: function saveTextAsFile(){ "use strict"; var textToWrite = document.getElementById("codeToSave").value; var textFileA

将textarea内容导出为html文件的Javascript函数在Internet explorer 11上不起作用,但在其他浏览器上起作用。它从单选按钮值(如“Output.html”)中获取文件名。我正在附加Javascript函数:

function saveTextAsFile(){
    "use strict";
    var textToWrite = document.getElementById("codeToSave").value;
    var textFileAsBlob = new Blob([textToWrite], {type:'text/html'});
    var fileNameToSaveAs = $('input:radio[name=exp-opt]:checked').val();

    var downloadLink = document.createElement("a");
    downloadLink.download = fileNameToSaveAs;
    downloadLink.innerHTML = "Download File";
    if (window.webkitURL != null){
        // Chrome allows the link to be clicked
        // without actually adding it to the DOM.
        downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
    }
    else
    {
        // Firefox requires the link to be added to the DOM
        // before it can be clicked.
        downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
        downloadLink.onclick = destroyClickedElement;
        downloadLink.style.display = "none";
        document.body.appendChild(downloadLink);
    }

    downloadLink.click();
}

function destroyClickedElement(event){
    "use strict";
    document.body.removeChild(event.target);
}

您可以尝试类似的方法:

function saveTextAsFile(){
    "use strict";
    var textToWrite = document.getElementById("codeToSave").value;
    var textFileAsBlob = new Blob([textToWrite], {type:'text/html'});
    var fileNameToSaveAs = $('input:radio[name=exp-opt]:checked').val();

    var downloadLink = document.createElement("a");
    downloadLink.download = fileNameToSaveAs;
    downloadLink.innerHTML = "Download File";
    // IE
    if (window.navigator.msSaveOrOpenBlob) {
        $(downloadLink).click(function(){
            window.navigator.msSaveOrOpenBlob(textFileAsBlob, fileNameToSaveAs);
        });
    // Chrome
    } else if (window.webkitURL != null){
        // Chrome allows the link to be clicked
        // without actually adding it to the DOM.
        downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
    // FF
    } else {
        // Firefox requires the link to be added to the DOM
        // before it can be clicked.
        downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
        downloadLink.onclick = destroyClickedElement;
        downloadLink.style.display = "none";
        document.body.appendChild(downloadLink);
    }

    downloadLink.click();
}

您的问题中有一个jQuery标记,因此我使用了jQuery,但是如果您希望避免使用jQuery,您可以使用纯JavaScript处理它。

您可以添加错误或一些控制台输出来获取有关您的问题的更多信息吗描述5:访问被拒绝。文件:template-js.js,行:324,列:2