Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function saveTextAsFile(fileNameToSaveAs, textToWrite) {
- var textFileAsBlob = new Blob([textToWrite], {
- type: 'text/plain'
- });
- var downloadLink = document.createElement("a");
- downloadLink.download = fileNameToSaveAs;
- downloadLink.innerHTML = "Download File";
- if (true) { //window.webkitURL !== null) {
- // Chrome allows the link to be clicked
- // without actually adding it to the DOM.
- downloadLink.href = window.URL.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();
- }
- downloadLink.click();
- SCRIPT5: Access is denied.
- window.navigator.msSaveBlob(blob, 'file.txt');
- window.navigator.msSaveOrOpenBlob(blob, 'file.txt');
- function saveTextAsFile(fileNameToSaveAs, textToWrite) {
- var ie = navigator.userAgent.match(/MSIEs([d.]+)/),
- ie11 = navigator.userAgent.match(/Trident/7.0/) && navigator.userAgent.match(/rv:11/),
- ieVer=(ie ? ie[1] : (ie11 ? 11 : -1));
- if (ie && ieVer<10) {
- console.log("No blobs on IE ver<10");
- return;
- }
- var textFileAsBlob = new Blob([textToWrite], {
- type: 'text/plain'
- });
- if (ie || ie11) {
- window.navigator.msSaveBlob(textFileAsBlob, fileNameToSaveAs);
- } else {
- 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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement