Redirect All Navigations to the Main Window of SiteKiosk

Today we are going to create a small script that will redirect all navigations to the main window of SiteKiosk. This can be helpful if you need to work with existing pages in a kiosk project that open new windows instead of navigating in one browser window only. If you can't change the behaviour of those pages you can use the SiteKiosk Object Model to create a solution.

The following script reacts to the OnInsert event that fires whenever a new window is added. It will check that the window is a SiteKiosk browser window and if it is, it will minimize it and trigger a navigation to the URL of the new window in the main SiteKiosk browser window. Once this happened the new window will be closed. Please note that you will see the new window for a very short time, this cannot be prevented. Depending on the nature of the navigation you also might have to increase the delay given for the new window to properly being created.

//Global variable
var gk_skwin = null;

//Event that fires when a new window is added to the list
SiteKiosk.WindowList.OnInsert = OnInsert;

//Function to call when a new window has been added
function OnInsert(skwin){
	//Write the WindowInfo object received as parameter to the global variable
	gk_skwin = skwin;
	//Add a little delay of 500 milliseconds to allow the window to be created properly
	SiteKiosk.Scheduler.AddDelayedEvent(500, MoveToMainWnd);

function MoveToMainWnd(){
	//Check if the type of the new window is a SiteKiosk browser window to make sure we don't try the following on any other window type
	if(gk_skwin.WindowType === 2){
		SiteKiosk.Logfile.Notification("DEBUG: New browser window detected, sending URL to main window"); //This line is for debugging purposes only
		//Minimize the new window to make it as much invisible as possible
		//Navigate to the address of the new window in the main window
		//Close the newly opened window

Copy the above code example to Notepad (or your preferred editor) and save it as a .js script file with whatever name you like, e.g. redirect2mainwnd.js. It is recommended to use the ..\SiteKiosk\html folder to store such files. Open the SiteKiosk configuration, go to Start Page & Browser or Browser Design (depending on the SiteKiosk version you are using), click on the Advanced button and add the script as an external script file. Save the configuration and start it with SiteKiosk. Whenever you are using a link now that will open an new window this navigation is redirected to the main SiteKiosk browser window and the new window will be closed.