There is a situation when you need to check user agent (means that website is open in pc or iphone).Here is a simple javascript function which you return that web page is open in which user agent.Please have a look on below example -
Example :You just need to copy the entire below code and paste it .Now check to open it in on pc and iphone by click on the "Check user agent" link.
<div onclick="checkUserAgent()"> Check user agent </div>
<script type="text/javascript">
function checkUserAgent(){
var userAgent = navigator.userAgent.toLowerCase();
var isIphone = (userAgent.indexOf('iphone') != -1) ? true : false;
if (isIphone) {
// For each event with an inline onclick
alert("Iphone");
}else{
alert("web");
}
}
</script>
If you like this post please don't forgot to notify me to post a comment .
Happy coding guys :)
Example :You just need to copy the entire below code and paste it .Now check to open it in on pc and iphone by click on the "Check user agent" link.
<div onclick="checkUserAgent()"> Check user agent </div>
<script type="text/javascript">
function checkUserAgent(){
var userAgent = navigator.userAgent.toLowerCase();
var isIphone = (userAgent.indexOf('iphone') != -1) ? true : false;
if (isIphone) {
// For each event with an inline onclick
alert("Iphone");
}else{
alert("web");
}
}
</script>
If you like this post please don't forgot to notify me to post a comment .
Happy coding guys :)