Page 2 of 3

Re: pgGotoURL

PostPosted: Sat Oct 27, 2018 7:09 am
by John Robin Dove
I've been testing your code to create a popup over an object on the page. It works well but I can't use a timer to bring it back into focus. Presumably the timer fires but nothing happens!

UPDATE: Apparently only a click as used in this example [url] https://www.mediacours.com/tb_examples/webtool2[url] can bring the popup back to the top. All other events have no effect. This is getting more and more frustrating. I wonder if there's a way I could identify pages that won't display in an iframe and use the popup system for them but use an iframe (pgGotoURL in a TB field) for all the others.

Re: pgGotoURL

PostPosted: Sat Oct 27, 2018 5:52 pm
by Clifton
Popup warnings are likely to be issued if you open your start page and do not auto-open the course. Instead provide a login for users that once accepted causes the TB window to launch. This shouldn't generate a warning because it was initiated by the user. It is auto-popups that tend to generate warnings.

Re: pgGotoURL

PostPosted: Sat Oct 27, 2018 5:56 pm
by Clifton
The timer fails to refocus the window because the system does not have to redraw the window. In you timer code use [win].moveBy(-1,0) followed by [win].moveBy(1,0). This will force the window back on top.

Re: pgGotoURL

PostPosted: Sun Oct 28, 2018 5:49 am
by John Robin Dove
re. popup warnings. Using the Sum Total launch page with Chrome I get no warnings.
Image
and with Firefox I just get this.
Image

re. timer

1) If I use the code you provided to open and position a popup how can I refer to the window in TB to be able to move it?

2) Using a normal HTML file moveBy doesn't move the window to the top.

Code: Select all
<script type="text/javascript">
 
  var w =  window.screen.width;
  var h =  window.screen.height;
  var windowRef;
  var q = w / 4;
  w = q * 3;
  var windowSetup = "left=" + q + ",top=0,resizable=yes,scrollbars=yes,status=yes,width=" + w + ", height=" + h;

  function openPopup() {
  windowRef = window.open("https://www.rspb.org.uk", "Document 1", windowSetup);
  };                                                                         

  function focusPopup() {
   if (windowRef)   {
//       setTimeout(windowRef.focus(), 1);
    windowRef.moveBy(-1, 0);
    windowRef.moveBy(1, 0);
    }
  };
 
  function setFocus()
   {
    var obj = document.getElementById("sf");
    obj.click();
   };
   
   function closePopup() {
   if (windowRef)   {
     windowRef.close();
    }
   };
   </script>

Re: pgGotoURL

PostPosted: Sun Oct 28, 2018 9:07 am
by Clifton
You can also use [windowRef].moveTo(). But if the window is already in the position needed, it won't actually accomplish anything. Each method has its purpose. But after calling either method, you need [windowRef].focus() to actually bring to the top of the browser stack.

Re: pgGotoURL

PostPosted: Sun Oct 28, 2018 10:04 am
by John Robin Dove
Still can't find a way to bring the popup to the top using a timer. Could you send me a tbk 9.01 example of this, please? Or perhaps I have misunderstood something.

Re: pgGotoURL

PostPosted: Sun Oct 28, 2018 12:21 pm
by Clifton
Please note that the timer has to fire from the parent window and not the popup window. The popup cannot focus itself, but the parent can focus, moveBy, and moveTo, the popup window because it is the "opener". Use some debug alerts to ensure you timer is firing correctly.

Re: pgGotoURL

PostPosted: Sun Oct 28, 2018 5:09 pm
by Clifton
Several modern browser security issues prevent raising a window to the top unless an actual user event occurs that focuses the popup window (i.e.: a button click is the only one that works and it cannot be synthesized).
You can try this code in the exec-js code page:
https://pgsoftwaretools.com/powerpac/assessments/exec-js/index.html
    var loadWin = function(url, alignToName, refresh) {
    var bds = { align : '', page : '', screen : '', titlebar : ''}, adj = 2, pos;
    if (alignToName) {
    bds.align = tbfunction_pgTBObjGet(alignToName, 'bounds').split(',');
    }
    bds.page = tbfunction_pgTBObjGet('page', 'bounds').split(',');
    bds.screen = [window.screenX, window.screenY, window.outerHeight, window.innerHeight];
    bds.titlebar = bds.screen[2] - bds.screen[3];
    pos = [ bds.align[0]*1 + bds.page[0]*1 + bds.screen[0]-adj,
    bds.align[1]*1 + bds.page[1]*1 + bds.screen[1] + bds.titlebar-adj*2,
    bds.align[2], bds.align[3] - Math.round(bds.titlebar/2.65)*2 ];
    /* Next line gives trouble in Chrome if "RefWindow" does not exist.
    Only set refresh to true for 2nd execution.
    This will be addressed in PowerPac v15 beta.
    ***/
    if (refresh) window.open('', 'RefWindow').close();
    return tbfunction_pgGotoURL("RefWindow", url, pos[0], pos[1], pos[2], pos[3], "",
    "scrollbars=1", true, true);
    };
    var frm = getToolBookFrame();
    frm.myWindow = loadWin('https://google.com', 'exec', false);
    frm.myWindow.focus();

    pgAddEvent(gTBo('returnVal', 'objRef'), 'click', function() {
    frm.myWindow.focus();
    });
    return 'click this field to move popup to top';
Any attempt to accomplish this with a timer has not been successful. Frankly, if browser focus could be used in a timer would give hackers and other malicious coders a lot of leverage. So I agree with the browser limitation here. However, if clicking an object immediately raises the popup, it would seem that this could still be useful to you.

NOTE: A bug fix in pgGotoURL() will require you to run this code using a page with the PowerPac v14.936.x.
 

Re: pgGotoURL

PostPosted: Mon Oct 29, 2018 11:32 am
by John Robin Dove
Hi Clifton,

Thanks for trying. I somehow guessed that a timer to refocus a popup window would not be allowed. It would be a nightmare if it were used to make advertisements keep popping back on top so I understand the reasons for this restriction. I'll have to settle for some other system. My best so far is this https://www.mediacours.com/tb_examples/webtool2 Maybe you had something like this in mind when you suggested i use a launch page.

Re: pgGotoURL

PostPosted: Fri Nov 09, 2018 3:54 am
by John Robin Dove
Hi Clifton,
Your code above posted on 29/10/18 no longer works. It definitely did the first time I tested it. Do I need a more recent version of the Powerpac?
John