/    Sign up×
Community /Pin to ProfileBookmark

script stopped working after adding another script

Hi experts
I don’t have big experience with writing javascripts but I managed to implement a script that I found on the net and adapted it slightly to create a pop-up window for pictures. This worked fine so far.
But after adding another script I wrote on my own that is called in the body tag with onload, my picture script does not work anymore.
It seems to me that the picture script is not executed at all as soon as I start another script with onload.
My second script hides a disclaimer text at the bottom of the page until you click on it.
I have prepared two variants of the page:
[url]www.bcbaden.ch/stories/2007/faas-indoor-sm.php[/url] where the disclaimer script is worting but not the picture script, and:
[url]www.bcbaden.ch/stories/2007/faas-indoor-sm_tst.php[/url] where the picture script works but the disclaimer is not activated.

Is it possible to have a solution for my problem as well as an explanation why this problems occurred (in easy words, remember I’m a newby) ?
I did not know for what I should have searched in this strange case, so please forgive me if I should have asked for something that an experienced user would have found on its own.

Thanks in advance for any help

Juerg

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@FangFeb 08.2009 — Change this:if (document.images) {
var openNewWin=false;
var onLoadBeforeImage=null;
var winName='newwin';
var ct=0;
if (window.onload)
onLoadBeforeImage=window.onload;
[COLOR="Blue"] window.onload=function() {
OpenPicInit();
InitDisclaimer();
}[/COLOR]
}
and remove the onload from the body.
Copy linkTweet thisAlerts:
@beckjauthorFeb 08.2009 — Thanks for the quick answer. However I want to keep the two script files independent of each other. On some of the pages I just need the pictures script and on other only the disclaimer script. On those that need both I have the problem.

Is there another solution that enables me to keep the scripts as they are ?

Thanks

Juerg
Copy linkTweet thisAlerts:
@FangFeb 08.2009 — Add this:if( window.addEventListener ) {
window.addEventListener("load", InitDisclaimer, false);
}
else if( window.attachEvent ){
window.attachEvent("onload", InitDisclaimer);
}
and remove the onload from the body.
Copy linkTweet thisAlerts:
@beckjauthorFeb 08.2009 — Thank you. Full success.

One question still remains: Why ?

I have read several tutorials but no one explains this effect. Is there an explanation ?

Best regards

Juerg
Copy linkTweet thisAlerts:
@criterion9Feb 08.2009 — When you use onLoad in the body tag it will only execute one function (the first one it comes across). If both script need executed you would either need to create a function that calls them both or use the dynamic solution from above.
×

Success!

Help @beckj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...