Search code examples
jqueryhref

Jquery Href - need to use on both mac and pc


I am writing an HTML program that will be accessed by over 500 people , in the html page i need to link it to pdf files from a side server - however I cant upload the webpage to the server,

The computers are split between macs and PC's , how can I use Jquery to detect what Operating system the computer is and from that decide which href link to use (as to get the file from the pc is using the server name KPA0DSOT10 - however from the mac I need to use "Volumes" , or is there a way in JQUERY to put one link forward and if it cant open it it will try another link ? - there are over 20,000 links on the one html page so if theres a quick and easy way to update them all without having to write out all the links again would be greatly appreciated!


Solution

  • Check the navigator.appVersion variable then modify all the links to a .pdf on the page accordingly. Do this from the .ready() function.

    $(document).ready(function() {
        if (navigator.appVersion.indexOf("Win") != -1) {
            // Computers runs windows
            $("a[href*='.pdf']").each(function() {
                this.href = this.href.replace("word_to_replace", "win_replacement");
            });
        }
        if (navigator.appVersion.indexOf("Mac") != -1) {
            // computer is a Mac
            $("a[href*='.pdf']").each(function() {
                this.href = this.href.replace("word_to_replace", "mac_replacement");
            });
        }
    }