3

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.

3
  • 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. Commented Apr 24, 2013 at 7:36
  • basically this file run locally not needed server Commented 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. Commented Apr 24, 2013 at 8:06

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm hesitating to downvote since this information is useful, but doesn't answer the question.
@MarioDeSchaepmeester : Edited my answer. Thanks for highlighting my mistake
0

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:

  1. Use your favourite AJAX library to send a request to the server to create the file
  2. 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
  3. 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.