I have a web page that pulls in several javascript files in the HEAD section. The path to one of those files is generated dynamically, and I’m seeing an issue with some paths that include the # character. For example, the following path does not resolve correctly, and therefore the .js file does not load (even though I’ve verified that it exists):
<script src="\\remote_machine\share\test\this is #3 test\test.js"></script>
I’m wondering what the special meaning of ‘#3’ is in this situation. I’ve tried replacing the # character with the equivalent html entity, like so:
<script src="\\remote_machine\share\test\this is #3 test\test.js"></script>
but that does not resolve the issue. Further, I notice that the following path does resolve correctly (assuming the file exists):
<script src="\\remote_machine\share\test\this is # test\test.js"></script>
Could anyone explain the meaning of ‘#3’ in the context of html as described? What’s the recommended fix?
EDIT: I’ve tried replacing the ‘#’ with “%23” in all three examples above. The first two remain broken, and the third no longer works. If I additionally replace all spaces with %20, I get the same result.
Apart from the issue with the hash and spaces (which should indeed be encoded as
%23and%20respectively), you’ve also got backslashes. Backslashes aren’t directory separators in URLs. A URL is not the same as a filename, and what you’ve got there isn’t even a filename, it’s a UNC path, for local-area Windows networking.There is no standard way to embed a UNC path in a URL; Windows networking has no place on the web and you shouldn’t include references to resources on a Windows network in a web page. That js needs to be on a proper web server that you can reference with normal HTTP URLs.
If you must try:
(Neither works on Safari.)