I am writing a local file using JavaScript and I am using IE for the same.
My code is as follows:
function savefile( f,g){
var w = window.frames.w;
if( !w ) {
w = document.createElement( 'iframe' );
w.id = 'w';
w.style.display = 'none';
document.body.insertBefore( w );
w = window.frames.w;
if( !w ) {
w = window.open( '', '_temp', 'width=100,height=100' );
if( !w ) {
window.alert( 'Sorry, could not create file.' );
return false;
}
}
}
var d = w.document;
d.open( 'text/xml', 'replace');
d.charset = "UTF-8";
d.write(JWPFormToHTML(f));
d.close();
var name= g.filename.value;
if( d.execCommand( 'SaveAs', false , name ) )
{
g.filename.value=name;
//document.getElementById("filename").value="";
alert('File has been saved.' );
}
else
{
alert( 'The file has not been saved.\nIs there a problem?' );
}
w.close();
return false;
}
The problem I am facing is the file is not getting saved as a UTF-8 encoded file, although I have added <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
to it.
Please help me on this or suggest some alternative to me.
NOTE: I would like a file manager to open before the file gets saved as in the case of execCommand
.