Pages

Tuesday, March 20, 2012

ใช้ jQuery ตรวจสอบว่ามีคนใช้ iPhone, iPod, iPad เข้าเว็บไซต์ของเรา

ผมจำต้องเขียน code โดยให้แสดงผลต่างกันระหว่าง Desktop browser กับ iOS Browser อย่างเช่น iPod, iPad หรือ iPhone

ซึ่งเราสามารถสั่งให้ Browser แสดงผลต่างกันได้ด้วย function ง่ายๆ นี้ครับ

function isiPhone(){
return (
(navigator.platform.indexOf("iPhone") != -1) ||
(navigator.platform.indexOf("iPod") != -1) ||
(navigator.platform.indexOf("iPad") != -1)
);
}

เวลานำไปใช้ก็เช่น

if( isiPhone() ) {
   window.alert("You are browing this site by iOS browser");
}

ที่มา: http://jquery-howto.blogspot.com/2010/09/iphone-ipod-detection-using-jquery.html

No comments:

Post a Comment