Call javascript functions on load and on window close
Copy link to clipboard
Copied
Hi guys,
is there a way to call a javascript function when the page is loaded and when the window of the browser is closed or changed. I know a can do that via js editing the html file, but is there a way to set that on captivate so that my client doesn't have to write it manually?
Thanks
Copy link to clipboard
Copied
Are you talking about using the JS window in Captivate?
I don't think you'll be able to do that. The window.onload event will already have passed by the time CP is loaded.
What do you mean about the client having to write it manually?
Copy link to clipboard
Copied
Yes, I'm talking about listening the js window events onbeforeunload and load from captivate itself.
I'm developing a captivate project that will be used ad starting point for other projects. If i could punt this scripts inside the project, my client wouldn't have to open every html file and write the script manually.
Copy link to clipboard
Copied
My suggestion then is to put the scripts in the head of an blank html page. Zip the file and insert on the first slide and display for rest of project. It will always be there then. I don't think you can get them to work from inside the JS window.
not sure this one will work, it may already be fired
window.parent.window.onload = function()
{
}
try this if it doesn't fire
window.onload = function()
{
}
window.parent.window.onunload = function()
{
}
Copy link to clipboard
Copied
That sounds like a great idea. I'll try that and let you know. Thanks!

