While working on Joomla, with infinite plugins and modules installed, I was facing the problem that Google Maps was not working on pages. After 4 hours of digging and frustrations, I finally found that one of my module was using JavaScript include in which windows.onload() event was called which is also called while loading Google Maps. So as the page was being loaded, windows.onload event of Google maps was called first and then windows.onload event of the module was called overriding event call of google maps.
Shit happens while coding and so was done by developers of the module.
Here is the learning part:
The javascript file of the module contained following code:
-
windows.onload = function()
-
{
-
localize();
-
var randomnumber = Math.floor(Math.random()*10000);
-
var date = new Date();
-
}
As this javascript file was loaded, the already loaded windows.onload function to load Google Maps was over ridden. Since, I had to use both the module as well as Google Maps plugin, this is how I altered the code:
-
var oldonload = window.onload;
-
if (typeof window.onload != ‘function’) {window.onload = loadShrekOnloader;}
-
else { window.onload = function() {if (oldonload){oldonload();}loadShrekOnloader();}}
-
-
function loadShrekOnloader()
-
{
-
localize();
-
var randomnumber = Math.floor(Math.random()*10000);
-
var date = new Date();
-
}
So the learning is never use windows.onload event stand alone especially when you are making module or third party service or widget. Always detect onloaded functions and append to them whatever you want to initiate.
Lot of learnings to do still. Happy coding
