Custom web component element to detect mobile browser, based on script here.
Install the component using Bower:
$ bower install is-mobile --save
Or download as ZIP.
-
Import Web Components polyfill:
<script src="bower_components/webcomponentsjs/webcomponents.min.js"></script>
-
Import the element:
<link rel="import" href="bower_components/is-mobile/is-mobile.html">
-
Use the element:
<is-mobile></is-mobile>
mobile
- boolean - indicates whether mobile browser is detected.
The attribute is set only once on the creation of the element.
It should not be set or overwritten, otherwise the value will be lost.
For example, this is how the element will appear on mobile browser:
<is-mobile mobile="true"></is-mobile>
Also, document.querySelector("is-mobile").mobile
will return boolean true
.