Change links on mobile devices

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

My idea is to dynamically change this link (but not the image) based on what type of device my user is connecting to. The main types of devices that I deal with are PCs, Google / Andriod, Ios, Amazon / Andriod.

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

+1
source share
2 answers

Javascript / jQuery will work for you. Let's say you used the code here to detect various mobile browsers: http://www.abeautifulsite.net/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.com');
}
+1
source

You can use CSS media queries for device sizes: http://css-tricks.com/snippets/css/media-queries-for-standard-devices/

OR you can use some server side discovery library , for example: https://code.google.com/p/php-mobile-detect/ p>

javascript: jQuery?

+1

All Articles