0

I am trying to target specific browsers and depending on the browser I would like to display different links. My issues is that I have some pdf portfolios but they will only open in IE and the rest of the browsers give a message to download adobe reader. My test code:

 var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
//For Firefox
if (browser == 'Firefox') {
    document.write('<a href="test.pdf" download="test.pdf">Download</a>');
}
//For Safari
if (browser == 'Safari') {
    document.write('<'+'a href="test.pdf" download="test.pdf">Download</a>');
} 
//For Chrome
if (is_chrome) {
    document.write('<'+'a href="test.pdf" download="test.pdf">Download</a>');
}
//For IE
if(document.documentMode) {
    document.write('<a href="test.pdf">View PDF</a>');
}

This is what I have pulled together from searching but is not working. I want to view the pdf if in IE or download it if it is in another browser.

jdbwizzard
  • 110
  • 1
  • 7

1 Answers1

0

Feature detection is recommended over browser detection but in your case I don't think that will help. Here is a good script to detect the browser: WhichBrowser

Santosh
  • 660
  • 7
  • 13