0

For a banner with a download link I want to conditionally add more then 1 link

If the user has Internet Explorer it will show the download link for Internet Explorer And if the user has Google Chrome or Safari it should display the link for that browser

feeela
  • 29,399
  • 7
  • 59
  • 71

3 Answers3

3

Use this to get browser info in PHP:

$info = get_browser(null, true);

It will return an array with the browser information. You can use that information to build the proper link from the server side. See the documentation for details: http://php.net/manual/en/function.get-browser.php

bfavaretto
  • 71,580
  • 16
  • 111
  • 150
  • What are the limitations of this? Seems to me browser sniffing can't work efficiently if its server-side. – Zach Lysobey Dec 27 '12 at 13:43
  • @Zach L It works as bad as client side browser sniffing as it relies on the information, that a browser sends with the HTTP headers. This is not reliable at all – as are any browser sniffing techniques. For example Opera has a button to switch as which browser it should identify itself to a server; some clients also send the footprints off multiple browsers at once. – feeela Dec 27 '12 at 13:47
  • The user agent header can always be spoofed, that's the limitation. – bfavaretto Dec 27 '12 at 13:48
2
navigator.sayswho= (function(){
    var N= navigator.appName, ua= navigator.userAgent, tem;
    var M= ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
    if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1];
    M= M? [M[1], M[2]]: [N, navigator.appVersion, '-?'];

    return M;
})();

THIS IS NOT MINE! It was posted by @kennebec on this other question: jQuery browser detection?

Community
  • 1
  • 1
the_marcelo_r
  • 1,847
  • 22
  • 35
2

If you want to detect Internet Explorer, You have to read about conditional comments. You do not need Javascript at all.

You can write:

<!--[if IE]>
<a href="ielink">some text</a>
<![endif]-->

<!--[if !IE]> -->
<a href="otherlink">some text</a>
<!-- <![endif]-->
loler
  • 2,594
  • 1
  • 20
  • 30