根据移动设备更改链接 [英] Changing links based on mobile device
问题描述
我有一个带有静态HTML链接的HTML img标签。
I have an HTML img tag with a static HTML link.
我的想法是根据用户连接的设备类型动态更改该链接(而不是图片)。我关心的主要类型的设备是PC,Google / Andriod,Ios,Amazon / Andriod。
My idea is to dynamically change that link (but not the image) based on what type of device my user is connecting from. The major types of devices I am concerned with are PC, Google/Andriod, Ios, Amazon/Andriod.
有一个HTML / CSS /是php / dom /服务器端的唯一选项?
Is there an HTML/CSS/Javascript solution to this, or is php/dom/server side the only options?
推荐答案
Javascript / JQuery会为你工作。假设您使用此处的代码检测不同的移动浏览器: http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-with-javascript/
Javascript/JQuery will work for you. Let's say you used the code from here to detect different mobile browsers: http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-with-javascript/
然后您就可以写如下:
if( isMobile.iOS() || isMobile.Android() ){
$('a#mylink').attr('href', 'http://newlink.com');
}
这篇关于根据移动设备更改链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!