1

is it possible to have a div tag that is visible only in specific devices? i want show a div just in browser android devices, and dont show this div in webview android.

<div class="android-devices"><a href="#">Android user please click here to download application</a></div>

Is this possible? I use wordpress

2 Answers2

2

You can achieve that with javascript.

Firstly add hide class to all your android-devices divs

And add this code to your css file:

.hide {
  display: none;
}

And add this to your javascript file

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1;
if(isAndroid) {
  var els = document.querySelectorAll('.android-devices');
  els.forEach(function(el) {
      el.classList.remove('hide');
  })
}

This code will detect android devices and will remove the hide classes from your divs.

UPDATE:

If you want to hide some divs on android, you can apply same logic.

Just use this line

el.classList.add('hide');

instead of this

el.classList.remove('hide');

And don't add hide class to your android-devices divs by default.

fatihsolhan
  • 565
  • 5
  • 19
0

You can do this by going through following steps

- Setting div to hidden initially ( HTML part )

  <div class="android-devices hide"><a href="#">Android user please click here to download application</a></div>

- Checking if current device is android device, if it is then show div ( JS part )

var isDeviceAndroid = /(android)/i.test(navigator.userAgent);
if( isDeviceAndroid  ){document.getElementsByClassName('android-devices').classList.remove("hide");

}

- Css part

.hide{display:none;}

Prashant
  • 151
  • 1
  • 11