javascript conditional onload - if the function is present...

This should be really easy, but I just can't seem to find the answer at the moment..

Consider onload event of the body tag -> if the BodyOnLoad function is in the page (either in the header or body), I would like to run it. If not do nothing (I stuck an alert in but doen't have to be there).

I may want to have BodyOnLoad in a separate js file, or right at the bottom, or not at all...

Many thanks in advance!
<html><head>
<script language="javascript" type="text/javascript"  > 
function BodyOnLoad()
{alert('1b');}
</sctipt>
</head>
<body onload="try{BodyOnLoad();}catch(e){alert('do nothing')}">
some text here...
</body>
</html>

Open in new window

CallConnectionAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ashish PatelCommented:
Try this way/.
<html><head>
<script language="javascript" type="text/javascript"  > 
function BodyOnLoad()
{alert('1b');}
</sctipt>
</head>
<body onload="if(!BodyOnLoad){alert('do nothing')}">
some text here...
</body>
</html>

Open in new window

0
Ashish PatelCommented:
Oops a small mistake. Please try this
<html><head>
<script language="javascript" type="text/javascript"  > 
function BodyOnLoad()
{alert('1b');}
</script>
</head>
<body onload="if(window.BodyOnLoad){ BodyOnLoad();} else {alert('do nothing');}">
some text here...
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pratima PharandeCommented:
Try this

You spell check for </sctipt> correct is
</script>

<html><head>
<script language="javascript" type="text/javascript"  >
function BodyOnLoad()
{alert('1b');}
</script>
</head>
<body onload="try{BodyOnLoad();}catch(e){alert('do nothing')}">
some text here...
</body>
</html>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.