troubleshooting Question

<body> onLoad function not working from javascript src

Avatar of Mark
Mark asked on
4 Comments2 Solutions1045 ViewsLast Modified:
I have a function:

<head><script lang="javascript">
function doThis()
  // do some things

In my html page I run this function onLoad:

<body onLoad="doThis();">

If I put this function in my <head><script> section right in the html page as shown,it works fine. If I try to put it in an external script file:

<script type="text/javascript" src="/myScripts/doThis.js"></script>

It doesn't work and I get an 'object not found' message indicating the <body> line. What's up? Please note that I have other scripts in external files and they work fine, just not this one. Is a script not permitted to be external if called from the <body> tag?


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros