File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Javascript on html with file object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Javascript on html with file object" Watch "Javascript on html with file object" New topic
Author

Javascript on html with file object

Kevin Du
Greenhorn

Joined: Jan 05, 2009
Posts: 6
Hi,

I am new to scripting with javascript and I am currently encouting an interesting problem. I've created a webpage which populate the combobox base upon the content of a folder. It is a simple page with a simple script and it work as a localhost but it would not work with a hostname. I know the reason why it doesn't work with hostname or when other accessing it but I've been trying to find way to get it work with a hostname and it would be great if any of you could let me know if it is possible.

Here's the html file



Here's the Javascript file popCombo.js.


It would work when I access it with http://localhost/Sample/index2.html but when I am trying to access it http://1.2.3.4/Sample/index2.html, it would give me the path not found error at: var myEnum = new Enumerator(myFolder.Files);


So far I've tried using relative path for the strFolderPath. Again, any help is much appreciated
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kevin Du
Greenhorn

Joined: Jan 05, 2009
Posts: 6
Sorry, was posting it for the first time. Thank you
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Much better. Now that your code is more readable, you are more likely to get useful responses.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The browser is most likely not allowing the ActiveX control to run (or limiting its ability to access the file system) for any host other than localhost.

This is a security feature I would expect.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Kevin Du
Greenhorn

Joined: Jan 05, 2009
Posts: 6
I guess a better question to ask is: Is there a way for me to do the same without using ActiveXObject?

I basically want to populate a drop down combo box with the links to the html files in that folder.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If the folder is on the client's machine then, no, you can't do this without some kind of privileged client side app running.
Applets operate in a similar sandbox.
In order for them to access the client's file system, the client would either need to alter their security policy to grant your application this access or, you would need to sign your applet with a certificate from a trusted Certificate Authority (CA) such as Verisign or Thawte. Even then, the user will have to authorize this action by clicking on a popup window that lets them know what the applet is going to do.

I imagine Flash has the same restrictions.

Think of what a malicious site could get from your machine if this wasn't the case.
Kevin Du
Greenhorn

Joined: Jan 05, 2009
Posts: 6
The folder is actually on the server side. I am not trying to access anything from the client.

Here's the folder structure on the server:
Website/index.html
Website/java.js
Website/HTML/ ---> this is where all other html pages which I need to populate to my combo box. These pages get generated daily. This is where I get stuck at. I've created a website for it and I can run the index.hml in localhost on the server and it would populate the combo box and work like a champ but when I try to access it from another computer via http://1.2.3.4/website/index.hml I would get path not found.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Ahh, well that's a horse of a different color.

What technology are you using on the server side (Servlets, PHP, ASP, etc)?
Kevin Du
Greenhorn

Joined: Jan 05, 2009
Posts: 6
Actually, never minded. I think it would be easier to do an ASP page for this.

Thanks,
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
I would add, don't use ActiveX if you want your website to be crossbrowser compatbile.

ActiveX is an IE proprietary scripting framework. It isn't going to work in all alternative browsers. This way you'll miss almost 40% of the market.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you want to read the contents of a directory and present them to the user, you'll need to write some server side code to do this.
For IIS, this is easiest to do with ASP or ASP.net.

This might not be the best forum (site) for help with ASP or .net.
We do have some members who work with .net a lot.
Maybe one of them will chime in with a link to a good .net forum.
Kevin Du
Greenhorn

Joined: Jan 05, 2009
Posts: 6
Thank you everyone for the inputs. A friend of mine explained it to me and I now understand why it wouldn't work.

Yeah, I'll do an asp site instead. For my temporary solution, I've created a vbscript to create a new index.html which populate the combo box with the new values.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Javascript on html with file object
 
Similar Threads
Passing values between PHP pages without navigation
Dynamic drop down list from an array
translate from English to Hindi
Javascript call bean setter
Javascript and PHP