0

I am writing a html file in which it needs to visit a third-party js file. The js file would access other resources using the protocol-less URLs, such as: <img src="//xxx/xx.png..>. When I upload the html and access the page through the website, the resources could be successfully visited. And the local webserver localhost:// works fine too.

However, if I double-click the html file and open it with a browser directly, these resources could not be accessed. I checked with Inspect Element and found the scheme was file://, and the URL of the resource that third-party 'js' file try to access turns to be something like: file://xxx/xx.png, which of course couldn't be found.

Since I couldn't modify the third-party js file, so my questions are:

  • Is where any way to specify the scheme manually?
  • Or how could I make the resources accessible in this condition?

I checked this answer, it indicates that this might be the drawbacks for protocol-less URL. But I am wondering since the scheme could be detected and set in the URL, it might be possible to set it directly.

Community
  • 1
  • 1
feihu
  • 1,935
  • 16
  • 24
  • You could always just use ` – e.marten Aug 27 '14 at 09:58
  • @Denocle the statement is written in the third-party file, I couldn't modify it. – feihu Aug 27 '14 at 13:50
  • Run your webpages from a webserver instead of local files. – Quentin Aug 27 '14 at 13:54
  • @Quentin, thanks for the information, I know it could work if I run it from a webserver. I want to know whether it would also work when running it as a local file. – feihu Aug 27 '14 at 14:10
  • 1
    If you can not manipulate the URL, then no, there is no way to get it work – it is called a protocol-_relative_ URL for a reason. – CBroe Aug 27 '14 at 14:18
  • A super hacky way of solving this would be to copy the third party JavaScript and change it to how you want it, OR write your own JavaScript to change the specific parts, of the third party script, to your needs. – e.marten Aug 27 '14 at 14:55
  • @Denocle, thanks, i could have a try. – feihu Aug 28 '14 at 02:24

0 Answers0