Link to home
Start Free TrialLog in
Avatar of BossTurbo
BossTurbo

asked on

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

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

Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

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
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
Avatar of BossTurbo
BossTurbo

ASKER

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?
>> 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
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.
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
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
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.