/    Sign up×
Community /Pin to ProfileBookmark

Sniffing out browser versions

Hello,
[INDENT]I’m pretty new to Javascript, so bare with me. I wrote this script to learn how to find a users browser version, and I can’t see where I made any errors, please take a look.[/INDENT]

[CODE]<script type=”text/javascript”>

if (navigator.appName == “Microsoft Internet Explorer”) {

document.write(” You’re running IE, which supports MARQUEE scrolling.”)

var builtInScroll = ‘<form name=”myForm”><MARQUEE ID=abc DIRECTION=LEFT
BEHAVIOR=SCROLL SCROLLAMOUNT=4>Finding the browser ver</MARQUEE><INPUT TYPE=”button” VALUE=”Start scrolling”
NAME=”startscroll” onClick=”document.all.abc.start()”><INPUT
TYPE=”button” VALUE=”Stop scrolling” NAME=”stopScroll”
onClick=”document.all.abc.stop()”></FORM>’;

}

else {

var builtInScroll = ‘<center><h1>Find browser version</h1></center>’

if (navigator.appName == “Netscape”) {
document.write(“You’re running Netscape, Doesn’t support for Marquee.”)
}

else {
document.write(“You’re not running MS IE or Netscape”)
}
}

alert(“navigator.appName is: ” + navigator.appName + “navigator.appVersion is: ” + navigator.appVersion)

document.write(builtInScroll)

</script>
[/CODE]

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledMar 01.2009 — there is two syntax error in your code: first, you can't put an end line character in the middle of a string. that is, you can type an "ENTER" inside a string. and second, you hasn't properly used a pair of quote in the string [b]builtScroll[/b].

it throw an error if you do:
<i>
</i>var string = 'a short
string';

//or

var string = 'a short string&amp;#8217;;
// opening string is doesn't match ending string which isn't a single quote char.


tips: use firefox browser with firebug extension or javascript console, or read the error thrown by browser which most likely tell you where is the error.
Copy linkTweet thisAlerts:
@Syphon101authorMar 01.2009 — Thanks, I downloaded Firebug right after I made the post. Should help be quite a bit with finding my common syntax errors.
Copy linkTweet thisAlerts:
@Syphon101authorMar 01.2009 — I'm still a bit lost on this part:

Firebug tells me:

missing ; before statement

var builtInScroll = "<form name="myForm"...aScript For Dummies...</MARQUEE><INPUT n

var builtInScroll = "<form name="myForm"><MARQUEE ID=abc DIRECTION=LEFT BEHAVIOR=SCROLL SCROLLAMOUNT=4>JavaScript For Dummies...</MARQUEE><INPUT

TYPE="button" VALUE="Start scrolling" NAME="startscroll" onClick="document.all.abc.start()"><INPUT TYPE="button" VALUE="Stop scrolling"

NAME="stopScroll" onClick="document.all.abc.stop()"></FORM>"
[/QUOTE]


I thought statements didn't have to end with a semicolin, and I'm not seeing where to put it before the statement.
Copy linkTweet thisAlerts:
@rpgfan3233Mar 01.2009 — var builtInScroll = [b][color=red]"[/color][/b]&lt;form name=[b][color=red]"[/color][/b]
myForm[b][color=red]"[/color][/b]&gt;&lt;MARQUEE ID=abc DIRECTION=LEFT BEHAVIOR=SCROLL SCROLLAMOUNT=4&gt;
// and so on


Notice anything unusual? I simply broke your code down to more than one line.
Copy linkTweet thisAlerts:
@Syphon101authorMar 01.2009 — Okay, not so much. Maybe I just don't understand Javascript syntax.

I understand that If you place more than one JavaScript statement on the same line, you must separate those statements with semicolons, but is this not one complete statement ?

Also, the book I am reading pretty much tells me to use single-quotes for the following statement ( Like the code above ). Looking at the book and my code only shows me nothing other than to use single-quotes in place of the double.

Notice anything unusual? I simply broke your code down to more than one line. [/QUOTE]

It does look unusual, heh. But I can not correctly identify the error.
Copy linkTweet thisAlerts:
@FangMar 01.2009 — All browsers support marquee, although it's not a valid element. It is making a return in css3

Makes your code somewhat redundant.
Copy linkTweet thisAlerts:
@rpgfan3233Mar 01.2009 — You have [i]var builtInScroll = "<form name="myForm" ..."[/i].

builtInScroll = "<form name=" //OK

myForm" ..." //What's wrong with this line (and pretty much the rest of the code)?

You used double quotation marks to enclose the string. The string already has double quotation marks, so all that you really have is a bunch of strings loosely placed next to various characters after that first bit like in the second line above where [i]myForm[/i] and [i]"[/i] are right next to each other? It would need an equality sign or something to be valid JavaScript. Of course, you'd have to do that for everything, and it really wouldn't work the way you wanted it to because then it wouldn't be HTML. Try single quotation marks. ?
Copy linkTweet thisAlerts:
@Syphon101authorMar 01.2009 — So, var builtInScroll = '<form name="myform">'; would be the correct way of doing this ?

If so, That's how I went about doing it in the first place. But I get 'unterminated string literal' error.
Copy linkTweet thisAlerts:
@ZeroKilledMar 01.2009 — So, var builtInScroll = '<form name="myform">'; would be the correct way of doing this ?[/quote]
that is one option, to use different quote for the opening string and the other quote inside the string. however, if you need to include the used quote for a string inside the string you have to escape it with the character . for example:
<i>
</i>var builtInScroll = '&lt;form name='myform'&gt;';


But I get 'unterminated string literal' error.[/quote]
that's probably because you inserted an end line between the string. when the interpreter read an end line it mean end of statement, the same meaning of a semicolon. what follow throw and error of unterminated string
<i>
</i>var builtInScroll = '&lt;form
name="myform"&gt;'
Copy linkTweet thisAlerts:
@Syphon101authorMar 01.2009 — Thanks for the help, I think I have a good understanding now.

Though, I begin to think learning JavaScript is a hopeless cause for me.
Copy linkTweet thisAlerts:
@FangMar 02.2009 — First burn the book you are learning JavaScript from; it has no relevance to modern scripting or html.

This is a good tutorial: http://www.yourhtmlsource.com/

Learn html first, without a basic understanding of valid semantic html, implementing JavaScript will remain an uphill struggle.
Copy linkTweet thisAlerts:
@Syphon101authorMar 02.2009 — Learn html first, without a basic understanding of valid semantic html, implementing JavaScript will remain an uphill struggle. [/QUOTE]
Well, I could only imagine how much more difficult it would be to learn JavaScript with out having a basic understanding of HTML ( Even though this book mentions you do not need to know html. ) But I do, and have learned HTML. I've written many many pages, read the HTML tutorial at w3schools before I started this book to refresh my memory, along with most of the JS tutorial.

This is a good tutorial: http://www.yourhtmlsource.com/[/QUOTE]

Thank you for the link anyhow, I did decide to read the HTML tutorial offered here anyways. I'm very determined to learn JavaScript.

Do they offer a decent JS tutorial ? Also, do you have any recommendations for modern JavasScript books ??
Copy linkTweet thisAlerts:
@MaydayMar 02.2009 — Their tutorials are pretty good:

http://www.tizag.com/javascriptT/index.php
×

Success!

Help @Syphon101 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...