Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword or section
Like this

Table Of Contents

0 of .
Results for:
No results containing your search query
P. 1
javascript FAQ

javascript FAQ



|Views: 529|Likes:
Published by sony

More info:

Published by: sony on May 28, 2008
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





About this FAQ
Why this FAQ?
The goal of this FAQ is to help you develop robust client-side scripts that canrun in Netscape Navigator as well as Microsoft Internet Explorer, under various operatingsystems. This FAQ collection is different from others in the following:
Here the answers are focused on platform-independent coding, rather than on one particular browser or platform.
Here most answers contain interactive code examples which you can run withoutleaving the Web page you are reading.
Here you get the solution, not just a confirmation that the problem exists. For example, other sources would just say:
Sorry, JavaScript cannot read files fromthe server 
. This FAQ gives you the solution:
 Here's a Java applet that helps JavaScript read files from the server.
What is JavaScript?
JavaScript is a scripting language designed for adding interactivity to HTML pages. The language was first implemented by Netscape Communications in Netscape Navigator 2 beta (1995). JavaScript is different from the Java language (developed at SunMicrosystems). However, the two languages can interoperate well.JavaScript programs, or scripts, are usually embedded directly in HTML files. The scriptexecutes when the user's browser opens the HTML file. (There is also
 server-side JavaScript 
, but it's beyond the scope of this FAQ collection.)JavaScript is an
interpreted language
. This means that scripts execute without preliminary
, i.e. without conversion of the script text into a system-dependent machine code. The user's browser 
the script, that is, analyzes andimmediately executes it. JavaScript is supported by the following browsers:
 Netscape Navigator (beginning with version 2.0)
Microsoft Internet Explorer (beginning with version 3.0)
Any other browser/product whose vendor licensed or implemented JavaScriptinterpreter (for example, Opera).Thus, most Internet users today have browsers that support JavaScript. That's whyJavaScript is one of the most popular tools for adding interactive features to Web pages.
JavaScript Features
What can JavaScript programs do?
The following list presents only some groups of typical tasks in whichJavaScript proves very useful:
Generating HTML pages on-the-fly without accessing the Web server . Below you'll find simple examples illustrating each of these tasks.
1. Giving the user more control over the browser.
Here you can change the background color of this page as well as the text onthe browser's status bar.And here is a
button implemented with JavaScript. Click it, and you'll return to the page from which you arrived:
2. Detecting the user's browser2. Detecting the user's browser and OS.
The ability to detect the user's browser and OSallows your script to perform platform-dependent operations, if necessary.
Here users of different browsers will get different greetings:
We are really glad to see a user of Microsoft Internet Explorer under Windows!
3. Performing simple computations on the client side.
This is a JavaScript calculator: type an arithmetic expression, and JavaScriptwill compute its value.
4. Validating the user's input.
In the calculator above, try typing some letters instead of numeric input. You'llget a warning:
 Invalid input characters!
  Note that JavaScript helps the browser perform input validation without wasting theuser's time by the Web server access. If the user makes a mistake in the input, the user will get an error message immediately! On the other hand, if the input information isvalidated only on the server, then the user would have to wait for the server response.
5. Handling dates and time.
 Example 1.
This is a JavaScript clock.Local time:
 Example 2.
This script says "Nice morning, isn't it?" or "Good afternoon!" or "Goodevening!" or "Wow, you are not asleep yet!?" depending on the current time. It also tellsyou today's date.
 Nice morning, isn't it? Today is Tuesday, 14 August 2007.
6. Generating HTML pages on the fly.
The Table of Contents on the left is dynamically expandable. To view allsubsections in a section, you can click on the white arrow corresponding to thatsection. To hide subsections, click on the arrow .Every time you click on the arrows, the browser generates and displays a new HTML page in the left frame. Thanks to JavaScript, this operation is performed on the clientmachine, and therefore you don't have to wait while the information goes back and forth between your browser and the Web server.
JavaScripter.net.Copyright© 1999-2006, Alexei Kourbatov
JavaScript Limitations
What can't JavaScript programs do?
JavaScript code cannot do any of the following:
use printers or other devices on the user's system or the client-side LAN(For a workaround, seePrinting JavaScript output.)
access files on the user's system or the client-side LAN ; the onlyexception is the access to the browser's cookie files.(For a workaround, see theFile Accesssection.)
access files on the Web server.(For a workaround, see theFile Accesssection.)
implement multiprocessing or multithreading.If you do need toaccess files or perform other "privileged" operations, you can use JavaScript in combination with a
 Java applet 
. Signed Java applets are allowed to do"privileged" things, and your JavaScript programs can exchange information withapplets. However, you have to bear in mind
the biggest JavaScript/Java limitation
: theuser can always disable Java or JavaScript or both!

Activity (2)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->