Forum Moderators: open

Message Too Old, No Replies

Call External Java at exit

         

Froog

11:30 pm on Mar 12, 2004 (gmt 0)

10+ Year Member



I want to call an external Java script (.js file) when the surfer exits my site.

Anyone? Thank you! :)

Birdman

3:37 pm on Mar 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think this should work:

<script type="text/javascript">
function doSomething()
{

}
</script>

<body onunload="doSomething()">

Rambo Tribble

2:30 am on Mar 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Let's clarify something: Java is the product of Sun Microsystems. It bears little relation to JavaScript, the product of Netscape and now administered by ECMA (a European standards group) under the name ECMAScript.

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.

Froog

10:48 pm on Mar 20, 2004 (gmt 0)

10+ Year Member



Ok now I am confused.

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]

tedster

11:57 pm on Mar 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In this situation you don't CALL the function in the head, you simply define the function so it's all ready for you to use onUnload.

<html>

<head>
<script type="text/javascript" src="[file that defines doSomething()].js">
</script>
</head>

<body onUnload="doSomething()">
[page]
</body>

</html>

Froog

12:12 am on Mar 21, 2004 (gmt 0)

10+ Year Member



This calls the script into action as soon as I load the page?

<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 :)

Rambo Tribble

2:10 am on Mar 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I guess the big question is what you want to do. So far we are only loading an external JavaScript file. The scripts in that file can only operate on the current window and its descendants (other windows it creates).

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.