onbeforeunload and seamless
February 10, 2017 12:00 AM
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?
Discussion (7)
Try replacing window with parent.window for seamless.
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);
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 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:
getDisplayWindow()
Returns the window objects that is to be used for dealing with the js objects generated by lectora and all window related attributes
getDisplayDocument()
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
GetCurrentPageDiv()
Returns an HTML element that represents the page div
GetCurrentPageID()
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
What I wrote above has nothing to do with closing windows. Did you try what I suggested?
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.
Discussions have been disabled for this post