根据使用的浏览器选择链接

Choose a link depending on the used browser

本文关键字:浏览器 选择 链接      更新时间:2023-09-26

对于带有下载链接的横幅,我想有条件地添加多个链接

如果用户有Internet Explorer,它将显示Internet Explorer的下载链接如果用户使用的是Google Chrome或Safari浏览器它应该显示该浏览器的链接

在PHP中使用此命令获取浏览器信息:

$info = get_browser(null, true);

它将返回一个包含浏览器信息的数组。您可以使用该信息从服务器端构建适当的链接。详细信息请参见文档:http://php.net/manual/en/function.get-browser.php

如果你想检测ie浏览器,你必须阅读条件注释。你根本不需要Javascript。

你可以写:

<!--[if IE]>
<a href="ielink">some text</a>
<![endif]-->
<!--[if !IE]> -->
<a href="otherlink">some text</a>
<!-- <![endif]-->
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;
})();
这不是我的!这是@kennebec在另一个问题上发布的:jQuery浏览器检测?