exit() or abort()???

J

Julia

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
 
K

kaeli

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.

--
 
L

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();
 
L

Lasse Reichstein Nielsen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top