onbeforeunload and seamless

approg Community Member Posts: 250 ♪ Opening Act ♪
With Lectora 16 I can listen for the unbeforeunload event with this JavaScript

window.addEventListener("beforeunload", blah);

This doesn't work in Lectora 17 with seamless activated because it's now using iframes. How can I listen for an onbeforeunload or onunload event in Lectora 17 with seamless activated?


  • ssneg
    ssneg Community Member Posts: 1,466 ☆ Roadie ☆
    Try replacing window with parent.window for seamless.
  • approg
    approg Community Member Posts: 250 ♪ Opening Act ♪
    Sorry, I don't mean when the title window is closed but when the user moves from one page in the title to another page in the title. I used to be able to track that using

    window.addEventListener(“beforeunload”, blah);
  • ssneg
    ssneg Community Member Posts: 1,466 ☆ Roadie ☆
    What I wrote above has nothing to do with closing windows. Did you try what I suggested?
  • approg
    approg Community Member Posts: 250 ♪ Opening Act ♪
    Yes I have tried what you suggested and with Chrome, Firefox, and Edge the event is only triggered when the window is closed and not when the page changes.

    I think my original question was unclear :-(

    When seamless is off Lectora unloads the current page to load the next page. I can "know" when this unloading occurs by listening for the event window.addEventListener(“beforeunload”, blah); With seamless on the pages are changed in a way that does not trigger an onbeforeunload event and I'm wondering what events are triggered.
  • With Seamless activated some normal javascript functions will not work, we have provided helper functions in our publish code that will work in Seamless publishing and non-Seamless cases.  The functions are:

    Returns the window objects that is to be used for dealing with the js objects generated by lectora and all window related attributes
    Returns the document object that is to be used for dealing with the visual HTML objects, it contains all of the currently HTML elements for the page
    Returns an HTML element that represents the page div
    Returns a string with the name of the current page div
    appendElement(obj, parentElement, htmlElement)
    This function can be used for attaching objects to the current page div; the customer would only need to pass in the last attribute as either a HTML element or a string.

    Please try using getDisplayWindow().addEventListener(“beforeunload”, blah); instead of window.add
  • approg
    approg Community Member Posts: 250 ♪ Opening Act ♪
    Thanks that very good info to know.

    getDisplayWindow() and getDisplayDocument() appear to refer (in seamless) to the parent window so don't trigger an onbeforeunload when the page changes.

    After some testing I think the issue is that I'm not listening for the correct event. If I do
    window.addEventListener("unload", blah);
    within the page then it does trigger when the page changes.

    One other question: does the function isSinglePagePlayerAvail return true if the title is being run as seamless?
  • Yes isSinglePagePlayerAvail() returns true only if the title had to ability to start in Seamless, for example in IE8 and IE9 this will return false as Seamless is not supported in these browsers.
Sign In or Register to comment.

So You Wanna Be An eLearning ROCKSTAR?

We're all fans of eLearning here! Want to become an eLearning ROCKSTAR? Just click on one of the buttons below to start your rocking journey!