Read User Agent

function isMobile()
{
	var uAgent = context.getUserAgent().getUserAgent();
	if (((uAgent.match("iPhone") !== null || param.platform=="iphone") || (uAgent.match("Android") !== null || param.platform=="android") || uAgent.match("iPad") !== null) || isIframe == true)
	{
		return true;
	}	
	else
	{
		return false;
	}
}

function isAndroidCheck()
{
	var uAgent = context.getUserAgent().getUserAgent();

	if ((uAgent.match("Android") !== null || param.platform=="android") || isAndroid == true)
	{
		return true;
	}	
	else
	{
		return false;
	}
}

function isIpad()
{
	var uAgent = context.getUserAgent().getUserAgent();
	print(uAgent);
	if (uAgent.match("iPad") !== null || param.ipad == 'true')
	{
		return true;
	}	
	else
	{
		return false;
	}
}

function isAndroidTablet()
{
	var uAgent = context.getUserAgent().getUserAgent();

	if ((uAgent.match("Android") !== null && uAgent.match("mobile") == null) || param.tablet == 'true')
	{
		return true;
	}	
	else
	{
		return false;
	}
}

function isIphone()
{
	var uAgent = context.getUserAgent().getUserAgent();

	if (uAgent.match("iPhone") !== null || param.platform=="iphone")
	{
		return true;
	}	
	else
	{
		return false;
	}
}

function isIOS5()
{
	var uAgent = context.getUserAgent().getUserAgent();

	if ((uAgent.match("iPhone") !== null  || uAgent.match("iPad") !== null) && uAgent.match('OS 5') !== null)
	{
		return true;
	}	
	else
	{
		return false;
	}
}





Snippet can be used to determine whether an XPage is accessed from a mobile device and which one.

JavaScript (Server)
Simon McLoughlin
February 14, 2012 2:44 AM
Rating
359

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...