exit function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • highway of diamonds

    exit function

    a bit of a 'hacker' with javascript but can any one tell me why this
    code throws up "'exit' is undefined" and how to sort.

    the code does what I want it to, but hate errors I can't explain.

    TIA

    R.

    code is:

    <script language="JavaS cript">
    //thanks to my mate geoff Taggart for this piece of code and style to round
    //corners a la explorer 5.5
    if (navigator.appN ame == 'Microsoft Internet Explorer' &&
    parseInt(naviga tor.appVersion) >= 4){
    document.write( '<fieldset>');
    exit;
    }
    else{
    document.write( '<fieldset class="moz_rad" >');
    exit;
    }
    </script>
  • Michael Winter

    #2
    Re: exit function

    On Fri, 27 Feb 2004 01:16:17 +0000, highway of diamonds
    <one@oneandonly .com> wrote:
    [color=blue]
    > a bit of a 'hacker' with javascript but can any one tell me why this
    > code throws up "'exit' is undefined" and how to sort.[/color]

    Because there is no such global variable, exit. There is no such global
    function either. In fact, even if you use return, which can be used to
    prematurely exit functions, it would serve no purpose as:

    1) That code is not part of a function, and
    2) The function would end after the 'else' clause anyway.
    [color=blue]
    > <script language="JavaS cript">[/color]

    The language attribute is deprecated. The type attribute is sufficient for
    specifying the scripting language and, more importantly, it is required.

    <script type="text/javascript">
    [color=blue]
    > if (navigator.appN ame == 'Microsoft Internet Explorer' &&
    > parseInt(naviga tor.appVersion) >= 4){[/color]

    Browser detection is a bad idea. For instance, my browser, Opera 7.23,
    will appear as IE according to that test if it is in spoofing mode.
    Furthermore, this script appears to make your page dependent on support of
    JavaScript that, depending on your execution environment, might not be
    available.

    However, without knowing what you're trying to acheive, there's no way to
    suggest a better solution.

    [snipped code]

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • Randy Webb

      #3
      Re: exit function

      highway of diamonds wrote:
      [color=blue]
      > a bit of a 'hacker' with javascript but can any one tell me why this
      > code throws up "'exit' is undefined" and how to sort.
      >
      > the code does what I want it to, but hate errors I can't explain.
      >
      > TIA
      >
      > R.
      >
      > code is:
      >
      > <script language="JavaS cript">[/color]

      Should be:
      <script type="text/javascript">

      The language attribute is deprecated in HTML4.01, forbidden in others.
      It is both forward and backwards compatible.

      [color=blue]
      > //thanks to my mate geoff Taggart for this piece of code and style to round
      > //corners a la explorer 5.5[/color]

      You got what you paid for - nothing.
      [color=blue]
      > if (navigator.appN ame == 'Microsoft Internet Explorer' &&
      > parseInt(naviga tor.appVersion) >= 4){[/color]



      And stop trying to figure out my browser, you can't.

      [color=blue]
      > document.write( '<fieldset>');
      > exit;
      > }
      > else{
      > document.write( '<fieldset class="moz_rad" >');
      > exit;
      > }
      > </script>[/color]

      And to answer your question, its because its not "exit" you want. Either
      break or return but you need neither. When it gets to the end of the
      sequence in the if/else's, it "exits" on its own.
      --
      Randy
      Chance Favors The Prepared Mind
      comp.lang.javas cript FAQ - http://jibbering.com/faq/

      Comment

      • highway of diamonds

        #4
        Thanks..

        <snip>

        Thanks for that lads, have taken your points on board.

        <blush> didn't realise I'd left Geoff's name in comments!</blush>

        R.

        Comment

        • Grant Wagner

          #5
          Re: exit function

          highway of diamonds wrote:
          [color=blue]
          > a bit of a 'hacker' with javascript but can any one tell me why this
          > code throws up "'exit' is undefined" and how to sort.[/color]

          The code throws up "'exit' is undefined" most likely because 'exit' is
          undefined in that Javascript. It's not on the list of reserved words for the
          language, and you haven't defined it anywhere.
          [color=blue]
          > the code does what I want it to, but hate errors I can't explain.[/color]

          I doubt very much it actually does what you want it to. You appear to be
          assuming there are two Web browsers in the world, IE 4 and higher versions, and
          Mozilla-based browsers (based the "moz" part of 'class="moz_rad "').
          [color=blue]
          > TIA
          >
          > R.
          >
          > code is:
          >
          > <script language="JavaS cript">
          > //thanks to my mate geoff Taggart for this piece of code and style to round
          > //corners a la explorer 5.5[/color]

          Of course, since IE doesn't support any of the Mozilla curve extensions, it's
          enough to write:

          <fieldset class="rad">
          </fieldset>
          <style type="text/css">
          fieldset.rad {
          -moz-border-radius: 10px;
          }
          </style>

          or whatever. IE and other browsers that don't understand "-moz-border-radius"
          will simply ignore it. No client-side Javascript required at all.
          [color=blue]
          > if (navigator.appN ame == 'Microsoft Internet Explorer' &&
          > parseInt(naviga tor.appVersion) >= 4){
          > document.write( '<fieldset>');
          > exit;
          > }
          > else{
          > document.write( '<fieldset class="moz_rad" >');
          > exit;
          > }
          > </script>[/color]

          --
          | Grant Wagner <gwagner@agrico reunited.com>

          * Client-side Javascript and Netscape 4 DOM Reference available at:
          *


          * Internet Explorer DOM Reference available at:
          *
          Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


          * Netscape 6/7 DOM Reference available at:
          * http://www.mozilla.org/docs/dom/domref/
          * Tips for upgrading JavaScript for Netscape 7 / Mozilla
          * http://www.mozilla.org/docs/web-deve...upgrade_2.html


          Comment

          Working...