The new GoogleMaps api defines a function to be called onunload of a page in order to prevent memory leaks.
At first I thought a "hook_onunload" function was missing from Drupal core, but this seems to have been replaced by a javascript addLoadEvent function in misc/drupal.js.
A addUnloadEvent function can be added as follows (modelled after the addLoadEvent function):
/**
* Adds a function to the window onunload event
*/
function addUnloadEvent(func) {
var oldOnunload = window.onunload;
if (typeof window.onunload != 'function') {
window.onunload = func;
}
else {
window.onunload = function() {
oldOnunload();
func();
}
}
}
Comments
Comment #1
jpulles commentedSorry for the typo. I meant that the 'hook_onload' function was replaced by addLoadEvent.
Comment #2
Ignas commentedDont work.
Placed this function into drupal.js, it 'adds' my function to unload list but unload function never fired.
Try yourself (js code, dont work):
Not nice solution is to add unload event into page.tpl.php: '' . (Works)
We need this function in drupal core! anybody hears?
Comment #3
magico commentedaddUnloadEventwas replaced by the jQuery$(document).ready().I think something like this could work (let's call javascript experts)
http://www.visualjquery.com/
Comment #4
brst t commentedCan this be done?
I'm currently using the method I found here : http://drupal.org/node/84972
Which I think would be comparatively clunky to a jQuery solution.
Comment #5
brst t commentedHm. Turns out adding this bit of code to the end of my script worked fine.
And, in keeping w/ the jQuery issue/subject, here, I did find a couple decent jQuery plugins for googlemaps:
http://www.dyve.net/jquery/?googlemaps
And as posted to the page: http://olbertz.de/jquery/googlemap.html
I don't quite have a very good handle on jQuery, yet...
Comment #6
robmilne commentedI want to have an unload event for WebFM since it creates many event closures on the DOM. Unfortunately I had to monkey with the garland theme to make it work. See http://vera-ikona.com/node/47
Comment #7
ricabrantes commentedresolved issue, Closed