1

I am working on a project that is based on this UCDavis Wayfinding Library. I have noticed that I am unable to successfully load my index.html page in my browser if I open it as a file.

Whenever I open it as a file with a URL something like:

file:///C:/Some/Folders/Here/index.html

I see this error in the js console:

XMLHttpRequest cannot load file:///C:/Some/Folders/Here/demo_map_2.svg. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

I understand what the error is telling me. And sure enough if I throw my project into Dropbox and access it via a public http link it works fine.

The part that I don't get though is why is it considered a Cross Origin request when the svg file is also stored locally, right alongside the html file?

Is there any way other than hosting the file under some sort of webserver (or similar service like dropbox) to get the .load() function to resolve successfully on a resource that is local to the same directory as the html file?

FoamyGuy
  • 45,328
  • 16
  • 118
  • 151
  • 1
    Problem is running off file protocol has different security restrictions and http. Run a local webserver and save yourself the trouble. OR you can run the browser with flags to allow local file access. http://stackoverflow.com/questions/18586921/how-to-launch-html-using-chrome-at-allow-file-access-from-files-mode – epascarello Apr 01 '15 at 13:34
  • You have 28k + reputation and you don't know that files have to be served by a web server? O_o How is that even possible? – Jeremy Thille Apr 01 '15 at 14:04
  • @JeremyThille My world is Android and Java. I am getting better but still bit of a noob on web stuff =x – FoamyGuy Apr 01 '15 at 14:07
  • Doesn't Java run on a web server? Or a server at all (Tomcat...)? I mean, servers are _everywhere_, it's lesson 1 in the book of web developers :) I don't really know how your stuff works, but it looks really different from web development. – Jeremy Thille Apr 01 '15 at 14:13
  • There are webservers that are built with java yes. But the vast majority of my work is on Android applications. So on any projects that do involve web servers I am nearly always the client to an existing web app. html and javascript are relatively recent additions to my toolbox. – FoamyGuy Apr 01 '15 at 14:34

0 Answers0