javascript - Changing links based on mobile device - Stack Overflow

I have an HTML img tag with a static HTML link. My idea is to dynamically change that link (but not the

I have an HTML img tag with a static HTML link.

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.

Is there an HTML/CSS/Javascript solution to this, or is php/dom/server side the only options?

I have an HTML img tag with a static HTML link.

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.

Is there an HTML/CSS/Javascript solution to this, or is php/dom/server side the only options?

Share Improve this question edited May 23, 2013 at 22:39 Legako asked May 23, 2013 at 22:22 LegakoLegako 331 gold badge2 silver badges8 bronze badges 1
  • Don't do it on the client, do it at the server. Client side browser or device detection is unreliable and requires constant maintenance. – RobG Commented May 24, 2013 at 3:27
Add a ment  | 

2 Answers 2

Reset to default 3

Javascript/JQuery will work for you. Let's say you used the code from here to detect different mobile browsers: http://www.abeautifulsite/blog/2011/11/detecting-mobile-devices-with-javascript/

Then you could write something like this:

if( isMobile.iOS() || isMobile.Android() ){
    $('a#mylink').attr('href', 'http://newlink.');
}

You might consider using CSS media queries for device sizes: http://css-tricks./snippets/css/media-queries-for-standard-devices/

OR you could use some sort of server-side detection library such as: https://code.google./p/php-mobile-detect/

OR you could use javascript: What is the best way to detect a mobile device in jQuery?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744869099a4598152.html

相关推荐

  • javascript - Changing links based on mobile device - Stack Overflow

    I have an HTML img tag with a static HTML link. My idea is to dynamically change that link (but not the

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信