exit() or abort()???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Julia

    #1

    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
  • kaeli

    #2
    Re: exit() or abort()???

    In article <eda25927.04060 71038.3220125b@ posting.google. com>,
    julia@scripteas y.com enlightened us with...[color=blue]
    > 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
    >[/color]

    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?



    Comment

    • Lee

      #3
      Re: exit() or abort()???

      Julia said:[color=blue]
      >
      >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.[/color]

      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(M ath.random())){
      alert("aborting ");
      return;
      }
      // main body of function
      }

      universe();

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: exit() or abort()???

        julia@scripteas y.com (Julia) writes:
        [color=blue]
        > Is there some way in Javascript to abort a script...not just a
        > function, but the entire script?[/color]

        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 - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        Working...