exit function

  • Thread starter highway of diamonds
  • Start date
H

highway of diamonds

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="JavaScript">
//thanks to my mate geoff Taggart for this piece of code and style to round
//corners a la explorer 5.5
if (navigator.appName == 'Microsoft Internet Explorer' &&
parseInt(navigator.appVersion) >= 4){
document.write('<fieldset>');
exit;
}
else{
document.write('<fieldset class="moz_rad">');
exit;
}
</script>
 
M

Michael Winter

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.

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.
<script language="JavaScript">

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

if (navigator.appName == 'Microsoft Internet Explorer' &&
parseInt(navigator.appVersion) >= 4){

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
 
R

Randy Webb

highway said:
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="JavaScript">

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

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

//thanks to my mate geoff Taggart for this piece of code and style to round
//corners a la explorer 5.5

You got what you paid for - nothing.
if (navigator.appName == 'Microsoft Internet Explorer' &&
parseInt(navigator.appVersion) >= 4){

http://www.jibbering.com/faq/#FAQ4_26

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

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

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.
 
H

highway of diamonds

<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.
 
G

Grant Wagner

highway said:
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 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.
the code does what I want it to, but hate errors I can't explain.

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"').
TIA

R.

code is:

<script language="JavaScript">
//thanks to my mate geoff Taggart for this piece of code and style to round
//corners a la explorer 5.5

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.
if (navigator.appName == 'Microsoft Internet Explorer' &&
parseInt(navigator.appVersion) >= 4){
document.write('<fieldset>');
exit;
}
else{
document.write('<fieldset class="moz_rad">');
exit;
}
</script>

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* 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-developer/upgrade_2.html
 

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
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top