URI path navigation issue
-
31-05-2021 - |
質問
My jquery code is
$(document).ready(function() {
if (navigator.appVersion.indexOf("Win") != -1) {
// Computers runs windows
$("a[href$='.pdf']").each(function() {
this.href = this.href.replace("Volumes", "KP01DS0194TG");
});
}
if (navigator.appVersion.indexOf("Mac") != -1) {
// computer is a Mac
$("a[href$='.pdf']").each(function() {
this.href = this.href.replace("KP01DS0194TG", "Volumes");
});
}
});
My link in my html side of it is <a href="file://///KP01DS0194TG/Quotes/Scanning/brother/Jobsheets/job no 12538.pdf">12538</a>
however the Jquery doesnt work because of the file://///
- if I take that out it works great, however I need it in there or else I can't connect to it - any ideas on what I can do to rectify this problem?
解決
A "file" URL needs 3 slashes:
1) file:// # protocol
2) /some/path/myfile.pdf # file and path, including leading "/" for root directory
This is true whether the OS is Windows ("\" backslash) or *nix
ALSO:
3) Spaces are bad. Consider naming your directories and files without spaces in them.
Otherwise, consider running "urlencode" on your path (which will convert spaces to "%20")
You might also be interested in the original RFC for URLs: