Link to home
Start Free TrialLog in
Avatar of Mark
Mark

asked on

<body> onLoad function not working from javascript src

I have a function:

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

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:

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

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?

ASKER CERTIFIED SOLUTION
Avatar of mr_egyptian
mr_egyptian
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CVSmarc
CVSmarc

if doesn't work, try
<script language="javascript" src="/myScripts/doThis.js"></script>
What is the path to your js file? The path you are using would be in the myScripts folder directly off of the web root (C:\inetpub\wwwroot\myScripts\doThis.js). Perhaps you meant it to be the myScripts folder under your web directory (C:\inetpub\wwwroot\yourapplication\myScripts\doThis.js) in which case your path should be:
<script type="text/javascript" src="/yourapplication/myScripts/doThis.js" />
SOLUTION
Avatar of SnowFlake
SnowFlake
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial