hegdepras
04-28-2006, 04:50 AM
Hi,
I want to save a .txt file to local system using javascript (without using ActiveX). The code is as follows.
<html>
<head>
<script language="javascript">
function saveVarsAsFile(a,b,c) {
try {
SaveFrame.document.open("text/html","replace");
SaveFrame.document.writeln(a) ;
SaveFrame.document.writeln("<br>") ;
SaveFrame.document.writeln(b) ;
SaveFrame.document.writeln("<br>") ;
SaveFrame.document.writeln(c) ;
SaveFrame.document.close() ;
SaveFrame.focus();
SaveFrame.document.execCommand('SaveAs',false,'C:\\tempfile1.txt') ;
} catch(err){
var strErr = 'Error:';
strErr += '\nNumber:' + err.number;
strErr += '\nDescription:' + err.description;
document.write(strErr);
}
}
</script>
</head>
<body>
<iframe id="SaveFrame" style="display:none"></iframe>
<A href="javascript:saveVarsAsFile('string1','string2','string3')">Write to a file</A>
</body>
</html>
The command docuent.execCOmmand takes 3 arguments, SaveAs, a boolean and default location of the file. Documentation for this command says that if we specify the second argument to 'true', the GUI for selecting the location to save the file will appear and if it 'false', GUI doesn't appear. When I execute the above html in IE 6.0, the GUI appears even though I have provided 'false' as second argument. I don't want that GUI to appear. Any solution for this?
Or is there any other solution to save a file to locan disk using javascript without using ActiveX?
Thank you.
I want to save a .txt file to local system using javascript (without using ActiveX). The code is as follows.
<html>
<head>
<script language="javascript">
function saveVarsAsFile(a,b,c) {
try {
SaveFrame.document.open("text/html","replace");
SaveFrame.document.writeln(a) ;
SaveFrame.document.writeln("<br>") ;
SaveFrame.document.writeln(b) ;
SaveFrame.document.writeln("<br>") ;
SaveFrame.document.writeln(c) ;
SaveFrame.document.close() ;
SaveFrame.focus();
SaveFrame.document.execCommand('SaveAs',false,'C:\\tempfile1.txt') ;
} catch(err){
var strErr = 'Error:';
strErr += '\nNumber:' + err.number;
strErr += '\nDescription:' + err.description;
document.write(strErr);
}
}
</script>
</head>
<body>
<iframe id="SaveFrame" style="display:none"></iframe>
<A href="javascript:saveVarsAsFile('string1','string2','string3')">Write to a file</A>
</body>
</html>
The command docuent.execCOmmand takes 3 arguments, SaveAs, a boolean and default location of the file. Documentation for this command says that if we specify the second argument to 'true', the GUI for selecting the location to save the file will appear and if it 'false', GUI doesn't appear. When I execute the above html in IE 6.0, the GUI appears even though I have provided 'false' as second argument. I don't want that GUI to appear. Any solution for this?
Or is there any other solution to save a file to locan disk using javascript without using ActiveX?
Thank you.