my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes Loading a javascript file with file:// Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Loading a javascript file with file://" Watch "Loading a javascript file with file://" New topic
Author

Loading a javascript file with file://

D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
Posts: 214
I have made a small static html page (Test.html) for testing purposes. In this page I load a javascript file from my local file system with:



(where <path> is the path to the file on drive f: ). Opening the file works fine in IE or FF with Open from the menu, or by entering the url "file:///c:/<pathwheremyhtmlfileis>/Test.html" in the browser address bar. I can also find the javascript file in the same way, by entering its url "file:///f:/.../jsfile.js" in the browser address bar (FF shows it as text, IE offers me to download the file, so I think its found).

Now I've put the exact same file into my apache docroot directory, and try to access it via "http://localhost:8080/Test.html". At first this didn't work in FF, because as I found out FF blocks "file://" requests that access the local file system when a page is loaded via http. There is a solution to that problem (you can set which websites are allowed). So I can display the file fine in FF.
In IE, the html file is found and I see it in the browser. But I get the error "Invalid character in jsfile.js line 1/char 1" (or similar) and another, stating that the function in the file is undefined. I googled and found that this means the file is not found (this is all IE8 btw). I tried to enable the scripting options for the local intranet zone, but that didn't help. Does anyone of you know which setting I can change so I can load the file correctly in IE too (if possible, not only IE8 but also earlier versions)?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60781
    
  65

What you have not explained is why you are using the file protocol in the first place. It makes no sense to do so.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
For security reasons browsers can not access files on the local computer system when the page is serverd from http. You can change your browser security settings to allow it, but that might not be wise.

Eric



D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
Posts: 214
Eric Pascarello wrote:For security reasons browsers can not access files on the local computer system when the page is serverd from http. You can change your browser security settings to allow it, but that might not be wise.

Eric


I thought it was a security problem (as I said, in Firefox you can explicitely set sites which should be allowed access), but HOW can I set this in IE? I tried to enable all the scripting related options in the internet options, but it still does not work.

As to why I want to do this: for development purposes. I thought it was the easiest way to work together with a (design) collegue for fine-tuning the css/javascript. I let our web app run in the jboss on my development pc. I have set the <style..> and <script..> paths so that they point to the corresponding directories on my collegue's pc. He accesses the web app on my pc via his browser but can edit the css and script files on his local pc (he has access to our cvs but hasn't got a jboss or IDE to compile and redeploy everytime he changes something). Apparently this method seems to work fine for the css, it only doesn't work for the javascript files.

Unfortunately I wasn't around when this web app was developed originally. My collegue says they did something similar back then so he could work in this fashion, but he can't recall how it was done. If there's another, better approach to this, please let me know.
D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
Posts: 214
Ok we got an idea for a better solution: we placed the css and javascript files into a local http server which both I and my collegue have access to. So now my collegue should be able to change the files there as he wishes, and we can integrate them into our web app when finished.

Sometimes you just don't think of the easy way first ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading a javascript file with file://
 
Similar Threads
Interacting with Internet Explorer
IE & FF how can I make absolute positioning work correctly
url redirection
ie conditional comment not working for xhtml file
how to assign my function to onclick