Accessing an External SiteKiosk Script from a Webpage

SiteKiosk offers you the option to run an external script in the background each time SiteKiosk is executed. This is useful to place more general SiteKiosk Object Model code and it can also be used to place variables and functions you want to use in between different web pages.

A simple external script file to illustrate the above can look like this:

var gstr_testvalue = "Default value";
 
function setTestValue(lstr_newvalue){
	gstr_testvalue = lstr_newvalue;
}
 
function retrieveTestValue(){
	return gstr_testvalue;
}

You can save this into a .js-file and add it to your SiteKiosk configuration as an external script.

To continue with our example we create an html page that changes the value of the gstr_testvalue variable. To demonstrate how to access a variable or a function of the external script the example page changes the value both directly and by using the setTestValue function that has been defined in the external script. To actually access the members defined in the external script the ScriptDispatch Object of the SiteKiosk Object Model is used.

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<title>Page that sets a new value</title>
<SCRIPT TYPE="text/javascript">
	//Initializing the SiteKiosk Object Model
	window.external.InitScriptInterface();
	
	function directVariableAccess(){
		//set the value 1 for the variable in the external script, this overwrites the existing value
		SiteKiosk.ScriptDispatch.gstr_testvalue = "Value created using direct access";
	}
	
	function functionBasedVariableAccess(){
		//set the value 1 for the variable in the external script, this overwrites the existing value
		SiteKiosk.ScriptDispatch.setTestValue("Value created using function-based access");
	}
	
//-->
</script>
<body>
	<input type="button" value="Direct Variable Write Access" onclick="directVariableAccess()">
	<br />
	<input type="button" value="Function-based Variable Write Access" onclick="functionBasedVariableAccess()">
</body>
</html>

Next we create an additional html page that retrieves the value from the external script. Again using a direct and a function-based method.

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<title>Page that reads the value</title>
<SCRIPT TYPE="text/javascript">
	//Initializing the SiteKiosk Object Model
	window.external.InitScriptInterface();
	
	function directVariableAccess(){
		//set the value 1 for the variable in the external script, this overwrites the existing value
		alert("Current value retrieved using direct access method: " + SiteKiosk.ScriptDispatch.gstr_testvalue);
	}
	
	function functionBasedVariableAccess(){
		//set the value 1 for the variable in the external script, this overwrites the existing value
		alert("Current value retrieved using function-based access method: " + SiteKiosk.ScriptDispatch.retrieveTestValue());
	}
	
//-->
</script>
<body>
	<input type="button" value="Direct Variable Read Access" onclick="directVariableAccess()">
	<br />
	<input type="button" value="Function-based Variable Read Access" onclick="functionBasedVariableAccess()">
</body>
</html>

The two html files can be placed locally on a SiteKiosk computer (e.g. in the html subfolder of the SiteKiosk installation folder) or on a web server. Just make sure that the location you placed the files under is allowed to execute the SiteKiosk Object Model.