jquery - Change web page content if user is on a mobile device -
i have link on website opens iframe in popup box using jquery. jquery script applies function link has specific attribute 'id=calcpop' can see here below.
<a href="calculator.html" id="calcpop">click here</a> it works great on computers, buggy on mobile devices. there way detect if user on mobile device , change not have 'id' attribute?
if can't use serverside language php, remove id using js – if have jquery, trick:
$("#calcpop").attr("id", ""); to detect whether on mobile device involved there lots of mobile devices.
you use like:
var ismobile = navigator.useragent.match(/mobile/i) != null; to find things mobile in ua (that match ipod/ipad/iphone), not sure others, you'd have check.
putting together, in document.ready closure:
var ismobile = navigator.useragent.match(/mobile/i) != null; if (ismobile) { $("#calcpop").attr("id", ""); } in php like:
<?php $ismobile = (bool) strpos($_server['http_user_agent'],'mobile'); if ($ismobile) { $id = "calcpop"; } else { $id = ""; } ?> <a href="calculator.html" id="<?= $id ?>">click here</a>
Comments
Post a Comment