Forum Moderators: open

Message Too Old, No Replies

Combining 2 scripts to run onload

OnLoad script

         

Ginxy33

10:13 pm on Feb 21, 2007 (gmt 0)

10+ Year Member



I have 2 javascripts, both of which need to be able to run on page load. I am having a hard time figuring out why this is not working. It's probably very easy but I an new to javascript.

Here is the code.

<script type="text/javascript">
//<![CDATA[
window.onload = function() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(37.0588, -93.3045), 16);
// Our info window content
var infoTabs = [new GInfoWindowTab("HERE", "<b> GRAYSTONE</b>")];
// Place a marker in the center of the map and open the info window automatically
var marker = new GMarker(map.getCenter());
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowTabsHtml(infoTabs);
});
map.addOverlay(marker);
marker.openInfoWindowTabsHtml(infoTabs);
}
if(!NiftyCheck())
return;
Rounded("div#nifty","all","#999999","transparent","smooth");
Rounded("div#nifty2","all","#999999","transparent","smooth");
Rounded("div#nifty3","all","#999999","transparent","smooth");
Rounded("div#niftybody","all","#999999","transparent","smooth");
Rounded("div#nifty4","all","#999999","transparent","smooth");
}
//]]>
</script>

I runs as long as it is on the map page, but if it is open on any other page, my NiftyCheck part of the script doesn't run. I am sure I have a bracket in the wrong place or something else totaly obvious. But I am pulling my hair out trying to find it. Help please?

StupidScript

9:46 pm on Feb 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sounds like the map page has a function (NiftyCheck()) that the others don't. That script will only run if NiftyCheck() returns true, so it's not running on the other pages because it doesn't return true.

s_mk

3:12 pm on Feb 23, 2007 (gmt 0)

10+ Year Member



try this function:

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload!= 'function') {
window.onload = func;
}
else {
window.onload = function() {
oldonload();
func();
}
}
}

originally written by Simon Wilson
[simonwillison.net ]

it rox...