• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Loading a javascript file with file://

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you have not explained is why you are using the file protocol in the first place. It makes no sense to do so.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic