1

I have the following script:

document.open("text","c:\\path\\to\\file\\browser.txt");

appendChild(navigator.appCodeName + ";");
appendChild(navigator.appName + ";");
appendChild(navigator.appVersion + ";");
appendChild(navigator.userAgent + ";");
appendChild(navigator.platform + ";");
appendChild(is_java + ";");

// ----------------------

if (is_opera) {
     appendChild("<TT>***Version numbers here are only valid</TT><BR>");
     appendChild("<TT>***if Opera is set to identify itself as Opera</TT><BR>");
     appendChild("<TT>***use is_opera vars instead</TT><BR>");
     }
     appendChild(is_major + ";");
     appendChild(is_minor + ";");

// ----------------------

if (is_opera) {
     if (is_opera7up) {
     appendChild(is_js);
         } else {
         appendChild(is_js);
         }
             } else {
             appendChild(is_js + ";");
             }

// ----------------------

appendChild(is_screen + ";");
if (window.screen) {
     appendChild(screen.height + ";");
     appendChild(screen.width + ";");
     appendChild(screen.availHeight + ";");
     appendChild(screen.availWidth + ";");
     appendChild(screen.colorDepth + ";");
}

// ----------------------

if (is_Flash) {
     appendChild(is_FlashVersion);
     } else {
     appendChild("unknown");
     }

document.close();

It does what I want it to do by collecting browser information. HOWEVER, it is not writing information to the file. How do I make it append the browser information to the text file?

You see the appendChild -- I also tried using document.write (which puts the information on the screen).

I am a Javascript newbie so please make your answers as straightforward as possible. Thank you.

9
  • You cannot simply create an arbitrary file via JavaScript hosted in a web browser. What is your rationale/end goal for this? Commented Aug 10, 2015 at 16:29
  • Use console.log() for such debugging purposes Commented Aug 10, 2015 at 16:31
  • shouldn't you be storing a reference to the document you opened? as in var myDoc = document.open("text","c:\\path\\to\\file\\browser.txt"); myDoc.appendChild(navigator.appCodeName + ";"); ... Commented Aug 10, 2015 at 16:32
  • What is your appendChild() function? What does it try to do? Where's the code for it? Commented Aug 10, 2015 at 16:35
  • @AlexK.: I'm just trying to log some browser information for users of a local intranet. Commented Aug 10, 2015 at 16:35

3 Answers 3

1

You can not do this. Beacuse browser can not write file.

You can use node.js https://nodejs.org/api/fs.html

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

Comments

0

You can generate a file for download. Check the solutions here:

Javascript: Create and save file, and Using HTML5/Javascript to generate and save a file

Comments

-2

This is a very common newbie Javascript question that you could answer for yourself with a quick Google search. Web browsers will not let you write files to the local filesystem.

(This question should be closed as a dup. For example: Is it possible to write to a file (on a disk) using JavaScript?)

2 Comments

I did a Google search but it seemed all that I was getting was Vbscript and ASP examples which, obviously, I don't want.
Okay. Well, the answer is "No". The browsers won't let Javascript write files to the local filesystem because it would be a security problem. Imagine the damage a malicious website could do if they could write files to disk.

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.