Is it possible in javaScript to create an html file in same directory ? After some searching on google I landed upon using ActiveXObject like this :-
var fso = new ActiveXObject("Scripting.FileSystemObject");
varFileObject = fso.OpenTextFile("C:\apache-tomcat-7.0.23\webapps\proof\web.html", 2, true,0);
varFileObject.write(data);
varFileObject.close();
But it is showing an error which is ActiveXObject is not defined or does not exist. I am not sure why this error is coming. Is this code browser specific?
I am using chrome and I need to write html file using javascript.
Please help me what can i modify in above code so that it can run. Or help me with some other alternative.
ActiveX Object works only in Internet Explorer. And browser is not allowed to make any changes to your file system. However if you need to save html page, then you have to do some extra things like send the url of html page or whole page as string to a server, host the server on localhost using tomcat and you can use java code to store the fetched url or string sent by you on your machine. I have done the same. If you need I can provide you the code too. (btw code is quite easy).
To fetch the page using URL you can use the Jsoup library which is very good html parser.
Hope this helps!