javascript - Why does this Js code (using userAgents) not work on my iphone 4? -
sorry ask such vague question can't pinpoint why code works on pc , on android phone not iphone 4 safari or chrome? checked browser compatibility .includes
, navigator.useragent
, .getelementbyid
.. missing?
html:
<p id="demo"></p> <button onclick="go()">click me</button>
js:
var devices = ["android","iphone","ipod","ipad","blackberry","chrome"]; var useragents = navigator.useragent; function detectdevice() { (var = 0; < devices.length; i++) { if (useragents.includes(devices[i])){ return devices[i]; } } } function go(){ var str = detectdevice(); document.getelementbyid("demo").innerhtml = str; }
any appreciated.
Comments
Post a Comment