Solved

Best way to write a text file on local machine w/Firefox ?

Posted on 2008-06-12
10
257 Views
Last Modified: 2013-12-07
I was trying to do it through javascript (which works on IE7, but only with a yes/no security box), below is the code.  This gives an error in firefox error console: "ActiveXObject is not defined".

OK... so is there a way to get javascript to do it?  Or is there another way to get firefox to write a file on the local machine or even better, a machine on the local network?  It doesn't have to be javascript, it can even be a 3rd party plugin or something.  There is no real server, just a bunch of workstations on a local network.

This is going to be running only my website and will not be connected to the internet, so I have no problems totally opening up the security options.


function WriteToFile()

{

var fso = new ActiveXObject("Scripting.FileSystemObject");

var FileObject = fso.OpenTextFile("C:\\_PhotosViewing\\order.txt", 2, true,0);

strOutput="blah blah"

FileObject.write(strOutput)

FileObject.close()

}

Open in new window

0
Comment
Question by:BossTurbo
  • 7
  • 3
10 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
Comment Utility
BossTurbo,

You can try installing the IETab addon (http://addons.mozilla.org/firefox/addon/1419) to your Firefox.  That could be a way to get your code to work, as long as Firefox security doesn't stop it.

Firefox doesn't support ActiveX objects natively.  They are an MS technology.  The addon is a way around this.

The other limitation, which the addon won't affect, is FIrefox's security.  If the page is a local page then this may work.  If it is an Internet page then the browser will not allow the page to mess with local files.  In Firefox you won't even get the security box.

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 54

Expert Comment

by:b0lsc0tt
Comment Utility
BossTurbo,

If you the security won't allow it then you will need to make an applet (i.e. Java applet) to do this.  The applet should be signed to for best results.  This probably isn't something you can download though, too specific, so you will have to develop it or have someone do it.  Applets can be allowed to do things like this, even in Firefox.

Let me know if you have a question.

b0lsc0tt
0
 

Author Comment

by:BossTurbo
Comment Utility
Hmm, I tried the IE tab and it does work kind of, it pops up an error dialog box when executing the ActiveX code, which is one of the reasons I'm avoiding the IE route in the first place.  I don't think the java applet will work since I have to pass variables from a javascript file that is in use on the page to the text file... the contents of a shopping cart.  I'm wondering if I can just pull the cart contents from a cookie file from a local system run vbscript and do the file management that way... a total hack, but if it works...  Thoughts?
0
 
LVL 54

Expert Comment

by:b0lsc0tt
Comment Utility
>> I'm wondering if I can just pull the cart contents from a cookie file from a local system run vbscript and do the file management that way... a total hack, but if it works...  Thoughts? <<

Would this be with script in the browser or just vbscript in something like a vbs file run locally?  If in a browser then it won't work.  Browsers are serious about security, especially protecting local files.  If the security alert in IE is too much for you then you are out of luck doing this in a browser.

Will the protocol in the URL of this be http:, file:, http://localhost, or something else?  It won't change what I just said but may affect options if you try to pursue an applet/object for the browser.

If you just mean a local vbs file then that will work.  Not my expertise but since it runs locally it will have the normal permissions to do things that the user has.  Reading a cookie's contents is not easy and that folder is a little protected by Windows but a vbs file can create and write a local text file.

bol
0
 

Author Comment

by:BossTurbo
Comment Utility
OK, I've just decided to use IE anyway, so far the only issue is the security error box when the activex object runs.  Any ideas around this?  I've read try using .hta file?  Or registering the script as a safe script??  Any ideas?  I'll give you points b0lsc0tt either way since you've helped.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 54

Expert Comment

by:b0lsc0tt
Comment Utility
Not with an hta or safe script setting.  What you mentioned above helped us rule them out earlier.  I haven't actually developed a toolbar so I don't know if there is something unique about them.  That may provide a way but the trouble would still be with the page.  The browser is going to still protect the page and content.

If an install is OK to provide this then you might look at a Browser Helper Object (BHO).  You can start by looking at http://msdn.microsoft.com/en-us/library/Bb250436.aspx .  From what I have read about them they may allow the type of control and access you want and need.

Other common IE development "tools" are listed at http://msdn.microsoft.com/en-us/library/aa753587.aspx .  I don't think any of those will be more useful but thought you might like the info and list.

Let me know if you have a question.  I am glad I have been able to help and hope this will be especially helpful.

bol
0
 
LVL 54

Expert Comment

by:b0lsc0tt
Comment Utility
Please disregard my comment above.  It is getting late and I mixed up questions.  I have to reread this and I will post a response (that actually makes sense). :)

bol
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 500 total points
Comment Utility
Here is my real response. :)

Since this isn't on a web server or an Internet page an HTA file may help.  IE may still bring up a security message but security is looser for an HTA.  They can only be run locally so it is expected that you are OK with what it does.  I do believe I have still seen some warnings though so it may not be much better.  I don't use them often enough to remember the differences.

To make the file you should be able to just rename the file.  Let it end with .hta instead of .htm or .html.  Then click on it with the mouse or run it to have the browser open the file.  These files will only work in IE.

Let me know how this helps.  Sorry about my previous post.  I will actually delete it later so the question is cleaner.

bol
0
 

Author Closing Comment

by:BossTurbo
Comment Utility
Hi b0lsc0tt,  Thanks for the time spent on the question, definetely helps alot even there is no clear solution.  There just is no way around IE's security box and firefox wont run activeX unfortunately.  The .hta file worked with no warning box, but has other issues.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
Comment Utility
Your welcome!  I'm glad I could help.

I have posted your grading comments below.  The info in them is helpful and at this time EE only shows them to the Asker and Experts with accepted/assisted comments.

Thanks for the grade, the points and the fun question.

bol

Grading Comments:
Hi b0lsc0tt, Thanks for the time spent on the question, definetely helps alot even there is no clear solution. There just is no way around IE's security box and firefox wont run activeX unfortunately. The .hta file worked with no warning box, but has other issues.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now