allowNavigation

Workarounds and usability notes.

allowNavigation

Postby John Robin Dove » Sat Oct 20, 2018 7:50 am

Hi Clifton,

I think the answer to my question is no but I'd like to make sure. I'm still chipping away at the conversion of my VS/VB.NET software to TB/Powerpac/JS. In most cases I have been able to replicate the original functions using either similar or sometimes very different coding techniques and I find that most DHTML objects have similar properties to VS objects.

One part of the program enables the teacher to display web pages. In VS I used a webBrowser object for this. It's just a built in, programmable version of Internet Explorer. One of its features that I found useful was its allowNagivation property. When this is set to false the user can only navigate to a site defined by the program. This means that students cannot while away their time visiting Facebook instead of doing an exercise for example.

I can't imagine that blocking navigation is a feature supported by many other browsers but I thought I'd ask. Thanks for your time.

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: allowNavigation

Postby Clifton » Sat Oct 20, 2018 8:57 pm

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!
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: allowNavigation

Postby John Robin Dove » Mon Oct 22, 2018 11:18 am

Hi Clifton,

Thanks for the code. I haven't come up with anything yet apart from the browser exit warning which I was already using. I now have a problem with pgGotoURL. I'll start a new topic as the subject is different.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron