By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,677 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

exit() or abort()???

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.