Using Browser Detection to Place SiteKiosk Object Model or Kiosk Project Specific Code

When you are doing a kiosk project with SiteKiosk you might plan to use web pages that are utilized for a kiosk browser as well as a normal web browser. In that case you don't want to create and maintain the web pages twice, therefore the kiosk code should be integrated into the normal code. To execute the kiosk specific code only on a kiosk system you need to detect that it is running in SiteKiosk. SiteKiosk provides you with two options for that.

One Option is to use the user agent. SiteKiosk uses the Internet Explorer WebBrowser control, therefore it has a user agent that identifies it as the underlying Internet Explorer. By default SiteKiosk adds SiteKiosk version information to the user agent. Here is an example of that:

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SiteKiosk 8.8 Build 1650)

The setting for the user agent can be found in the configuration of SiteKiosk under Start Page & Browser -> Advanced Computer Identification. There you will also find an option to add any text you want to the user agent. The following is an example that bases the browser detection on the user agent:

<html>
<head>
	<title>SiteKiosk User Agent Example</title>
</head>
	<body>
		<span id="SiteKioskOrNot">...</span>
	</body>
	<script type="text/javascript">
		if (navigator.userAgent.indexOf("SiteKiosk") !== -1){
			document.getElementById("SiteKioskOrNot").innerHTML = "You are using SiteKiosk.";
			//Place code for your kiosk project here.
		}
		else{
			document.getElementById("SiteKioskOrNot").innerHTML = "You are not using SiteKiosk.";
			//Place code for normal web browsers here.
		}
	</script>
</html>

 

The other option is to use try-catch in your code. This option is only suitable when you explicitly want to use the SiteKiosk Object Model as part of your kiosk project code. The try-catch basically tries if the initialization of the SiteKiosk Object Model works or not. Here is the code example for that:

<html>
<head>
	<title>SiteKiosk Try-Catch Example</title>
</head>
	<body>
		<span id="SiteKioskOrNot">...</span>
	</body>
	<script type="text/javascript">
		try{
			window.external.InitScriptInterface();
			document.getElementById("SiteKioskOrNot").innerHTML = "You are using SiteKiosk.";
			//Place code for your kiosk project here.
		}
		catch(e){
			document.getElementById("SiteKioskOrNot").innerHTML = "You are not using SiteKiosk.";
			//Place code for normal web browsers here.
		}
	</script>
</html>

Note that you need to allow script permission for the SiteKiosk Object Model to be executed in SiteKiosk. You can do this in the configuration of SiteKiosk under Access/Security -> URLs with Script Permission. Another example for the try-catch option can be found in the SiteKiosk Object Model documentation at the bottom of this page.