I have a web page i want that when user click on button then it must create a doc file which contains the following information like Name etc and Designation we have libraries in php and .net to create a file , so is there way in html so that we can create files in root folder of project.
-
HTML en javascript are client-side technologies, so you will not be able to create a doc file in the root folder of your server application directly. However, with javascript you can send JSON to your server, where you will be able to make the doc.MarioDS– MarioDS2013-04-24 07:36:28 +00:00Commented Apr 24, 2013 at 7:36
-
basically this file run locally not needed serverJdeveloper Iphone– Jdeveloper Iphone2013-04-24 07:39:29 +00:00Commented Apr 24, 2013 at 7:39
-
So now you are asking if a website can write 400 billion files on a user's computer when they click on a button. The answer is again: No.7stud– 7stud2013-04-24 08:06:58 +00:00Commented Apr 24, 2013 at 8:06
2 Answers
You cannot create them on server as HTML and JS both are for client-side only. Even then, if you wish to do something like this client-side in future, use the following info :
Two methods are defined in the specifications, 1) createDocument from DOM Core Level 2 and 2) createHTMLDocument from HTML5.
The former creates an XML document (including XHTML), the latter creates a HTML document. Both reside, as functions, on the DOMImplementation interface.
var impl = document.implementation,
xmlDoc = impl.createDocument(namespaceURI, qualifiedNameStr, documentType),
htmlDoc = impl.createHTMLDocument(title);
Actually, these methods are rather young and only implemented in recent browser releases. According to http://quirksmode.org and MDN, the following browsers support createHTMLDocument:
Chrome 4
Opera 10
Firefox 4
Internet Explorer 9
Safari 4
You can create a HTML document in older versions of Internet Explorer, using ActiveXObject:
var htmlDoc = new ActiveXObject("htmlfile");
The resulting object will be a new document, which can be manipulated just like any other document.
HTML and JavaScript run on the client, but to create a file in the root folder of the project requires a procedure on the server. Luckily, there is a common standard technology for this form of communication: AJAX. Your process might run like this:
- Use your favourite AJAX library to send a request to the server to create the file
- Write the code on the server in PHP or .NET using your existing libraries, which will accept the request, create the file and return the URL
- Display the URL in your page for a user to download.
If you use JQuery, or any other standard JavaScript framework, they'll have an AJAX library already built in.