Home  >  Article  >  Web Front-end  >  Two ways to write xml files under IE (fso/saveAs)_Basic knowledge

Two ways to write xml files under IE (fso/saveAs)_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:26:501272browse

For security reasons, browsers such as Firefox do not support writing local files.
You can write xml files in the following ways under IE

Method 1: fso

Copy code The code is as follows:

// LoadXML() See the previous article for reading XML under IE
var xmlDom = loadXML("config.xml");
var contentText = "";
if(typeof xmlDom.xml != 'undefined') {
contentText = xmlDom.xml;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.CreateTextFile ("D:\test\test.xml", true);
file.Write(contentText);
file.Close();

Create text file
CreateTextFile (filename, overwrite, unicode)
filename: file name
overwrite: if the file exists, whether to overwrite it; the default is false
unicode: whether the content of the file is stored as unicode text; the default is false

Method 2: saveAs
embed a hidden iframe in the page,
Copy the code The code is as follows:



Write xml content into iframe , save as file.
Copy code The code is as follows:

var frame = window.frames["export"];
frame.document.open();
frame.document.write(contentText);
frame.document.execCommand("saveAs",true,"test.xml");
frame. document.close();

In addition, IE XMLDOM has a save method
prompting that there is no permission. I browsed the security policy settings of IE and found no place where permissions can be modified
The method should not be feasible.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn