Forum Moderators: open
A external script file must be loaded by the inclusion in the head of an HTML document of code like:
<script type="text/javascript" src="scriptFile.js">
</script>
A function in the already loaded .js file can then be run on the HTML document's unload, as Birdman has shown. Keep the function short, or it may not complete.
Here is what I want to do:
I want to call this file: 12.js after the surfer closes the browers or just plain exits.
here is what I tried:
<script type="text/javascript">
function doSomething()
{
<script type="text/javascript" src="http://www.example.com/12.js">
</script>
}
</script>
<body onunload="doSomething()">
______________
If I call the .js in the head all by itself it goes into effect, I only want it to work after they exit or leave the page. Thanks for your help you guys seem to know a lot. Can some one just post the exact code I would need to do this?
[edited by: tedster at 11:52 pm (utc) on Mar. 20, 2004]
[edit reason] use example.com, not specific [/edit]
<html>
<head>
<script type="text/javascript" src="12.js">
</script>
</head>
<body onUnload="doSomething()">
[page]
</body>
</html>
I am a complete fool with this stuff can some one look at what I want and just post it? Thank you :)
I just want the 12.js file to load on exit.
I need the whole code not bits, I am a newbie :)
This means that once you leave the current page, scripts invoked by it are toast. To load a script file on unload (unload is when the page is closed by the browser) would accomplish nothing; as soon as (or even before) the script file finished loading, it would be unavailable.