Use for $currentDeviceType to show different homepages

1
Hello,  I want to use  $currentDeviceType to show different homepages on Tablet/Phone, but this variable always shows “Desktop”, even if i log in on a Ipad/Iphone. I have already configured the “Phone web” and “Tablet web” in navigation. I use a published sandbox app for the testing. Is there another way to detect the current device ? Thanks
asked
1 answers
1

Hi Peter, 

 

“$currentDeviceType happens by examining the User-Agent  string that is sent by the device”

https://docs.mendix.com/refguide/navigation/#redirection

 

Perhaps you can create a JavaScript and use within a nanoflowHelper 

/**
 * @returns {Promise.<string>}
 */
export async function JavaScript_GetDeviceType() {
	// BEGIN USER CODE
	const ua = navigator.userAgent;
	if (/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(ua)) {
    	return "tablet";
  	}
  	if (/Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(ua)) {
    	return "mobile";
  	}
  	return "desktop";
	// END USER CODE
}

 

Another approach is with MediaQueries 

“Using media queries allow us to adjust our styles according to factors like the type of device used, the viewport size, the screen’s pixel density, or even the device orientation”

https://academy.mendix.com/link/modules/475/Responsive-UI

 

Best regards

 

answered