Best you can do is make use of the browserExitWarning() function to at least keep the student from closing a page which is part of the learning process.
To prevent switching away from a tab or browser window is very difficult to get working in modern browsers. Browsers allow you to detect when the window is no longer active, but they will not force the user back to the previously active window. You can search for solutions on this one and some have posted code, but I've yet to see it consistently work. About all I've seen work is the code will fire an event when user switches away, but there is no way to force them back to the learning window.
Please post a solution if you find one that works for you.
I played around with the following in a single page export using XML:
- Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<page>
<config delay="">
<!--Configuration tags (e.g.: <stylesheet> and <javascript> tags;
can also include PowerPac function tags; etc.)-->
</config>
<!--Add make tag at level 0 to hold our response code regardless of page navigation.-->
<make id="sharedActions" type="div" level="0" dims="-100,-100,5,5" class="" refObj="" autoAlign="" replace="">
<!--Style new object as required-->
<style>
<![CDATA[
{ "display" : "none" }
]]>
</style>
<!--Create a user event function-->
<function name="myfocus" event="user" params="e">
<![CDATA[
/* CLIFTON: Create a function which auto focuses this window when a timer event fires.
***/
//alert(e.data + " > " + e.target.id);
var w = this.ownerDocument;
w = w.defaultView || w.parentWindow;
w.focus();
]]>
</function>
</make>
<config2 delay="500">
<exeJavascriptDirect>
<![CDATA[
/* Next line uses a timer to refocus the learning window.
It works and sends the user event and window attempts to refocus itself
but it will not become topmost and active.
***/
tbfunction_pgTimer(true, 3000, 'sharedActions');
/* Next code detects when user switches away and fires the
onchange event. You maybe could leverage this to at least run
code when the user switches away and back again.
***/
(function() {
var hidden = "hidden";
// Standards:
if (hidden in document)
document.addEventListener("visibilitychange", onchange);
else if ((hidden = "mozHidden") in document)
document.addEventListener("mozvisibilitychange", onchange);
else if ((hidden = "webkitHidden") in document)
document.addEventListener("webkitvisibilitychange", onchange);
else if ((hidden = "msHidden") in document)
document.addEventListener("msvisibilitychange", onchange);
// IE 9 and lower:
else if ("onfocusin" in document)
document.onfocusin = document.onfocusout = onchange;
// All others:
else
window.onpageshow = window.onpagehide = window.onfocus = window.onblur = onchange;
function onchange (evt) {
//Enter your code in this function when user switches back and forth.
var v = "visible", h = "hidden",
evtMap = {
focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h
};
evt = evt || window.event;
if (evt.type in evtMap)
document.body.className = evtMap[evt.type];
else
document.body.className = this[hidden] ? "hidden" : "visible";
};
// set the initial state (but only if browser supports the Page Visibility API)
if( document[hidden] !== undefined )
onchange({type: document[hidden] ? "blur" : "focus"});
})();
]]>
</exeJavascriptDirect>
</config2>
</page>
Let us know what you come up!