469,356 Members | 2,013 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

exit() or abort()???

Is there some way in Javascript to abort a script...not just a
function, but the entire script? Most languages I've used have
something like an exit or abort function. I want to be able to alert
the user with a message, and then just have the script stop dead where
it's at. Is this possible? Thx, Julia
Jul 23 '05 #1
3 98067
In article <ed**************************@posting.google.com >,
ju***@scripteasy.com enlightened us with...
Is there some way in Javascript to abort a script...not just a
function, but the entire script? Most languages I've used have
something like an exit or abort function. I want to be able to alert
the user with a message, and then just have the script stop dead where
it's at. Is this possible? Thx, Julia


If you want to do this, you should put all the code in a function and
use the return statement.

I am unaware of any exit or abort in JS.

--
--
~kaeli~
Can you be a closet claustrophobic?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
Lee
Julia said:

Is there some way in Javascript to abort a script...not just a
function, but the entire script? Most languages I've used have
something like an exit or abort function.


Those other languages allowed you to exit() or abort() from
a function or procedure. The Javascript "return" statement
will do the same thing. Just put your code in a function
and invoke it, rather than let it run in-line.

function universe() {
if(Math.round(Math.random())){
alert("aborting");
return;
}
// main body of function
}

universe();

Jul 23 '05 #3
ju***@scripteasy.com (Julia) writes:
Is there some way in Javascript to abort a script...not just a
function, but the entire script?


You can make an error or throw an exception.

Examples:
Error:
null.dummy;
Exception
throw "exit";

If you don't want the browser to complain, you need to catch the
exception at the top. Some browsers allow you to catch an error
by defining an "onerror" handler on the document or window (don't
remember which).

Exceptions are not available in IE 4 or Netscape 4 (or contemporary
browsers).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Morris | last post: by
4 posts views Thread by Chuck | last post: by
20 posts views Thread by Doug Thews | last post: by
18 posts views Thread by Urs Vogel | last post: by
8 posts views Thread by Martin Eisenberg | last post: by
3 posts views Thread by Chip | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.