Skip to main content

Javascript

Question: What is JavaScript?

Answer: JavaScript is a scripting language designed for adding interactivity to Web pages. The language was first implemented by Netscape Communications in Netscape Navigator 2 beta (1995). JavaScript is different from the Java language (developed at Sun Microsystems). However, the two languages can interoperate well.

Client-side JavaScript programs, or scripts, are usually embedded directly in HTML source of Web pages. (Note: There is also server-side JavaScript, but it's beyond the scope of this FAQ collection.) Depending on the Web developer's intent, script code may run when the user opens the Web page, clicks or drags some page element with the mouse, types something on the keyboard, submits a form, or leaves the page.

In most existing implementations, JavaScript is an interpreted language. This means that scripts execute without preliminary compilation, i.e. without conversion of the script text into system-dependent machine code. The user's browser interprets the script, that is, analyzes and immediately executes it. JavaScript is supported by the following browsers:

* Netscape Navigator (beginning with version 2.0)
* Microsoft Internet Explorer (beginning with version 3.0)
* Firefox
* Safari
* Opera
* Google Chrome
* Any other browser whose vendor licensed or implemented JavaScript.

Thus, most Internet users today have browsers that support JavaScript. That's why JavaScript is one of the most popular tools in the Web developer's arsenal.

Question: Where can I get JavaScript documentation?

Answer: Online JavaScript documentation is available at these sites:

* http://www.mozilla.org/js/language/ - Mozilla.org JavaScript Resources page
* http://msdn.microsoft.com/en-us/library/72bd815a.aspx - JScript at Development Tools and Languages section of MSDN Library.
* http://msdn.microsoft.com/en-us/library/hbxc2t98.aspx - JScript at Web Development and Scripting section of MSDN Library.

In addition, you can find JavaScript discussions, online tutorials, links, code examples, and hundreds of useful scripts at the following sites (of course this list is incomplete and serves only as a starting point):

* http://www.WebReference.com/programming/JavaScript/ - tutorials and in-depth discussions
* http://www.irt.org - FAQ collections in several categories, including JavaScript
* http://www.JavaScripts.com - lots of scripts and code examples
* http://www.JavaScripter.net/faq/ - this FAQ collection.


Question: How do I insert comments in JavaScript code?

Answer: JavaScript supports three different types of comments:

1. Multiple-line C-style comments. Everything between /* and */ is a comment, for example:

/* This is a comment */
/* C-style comments can span
as many lines as you like,
as shown in this example */

2. One-line comments of C++ style. These comments begin with // and continue up to the next line break:

// This is a one-line comment

3. One-line comments with the HTML comment-opening sequence (). Consider this example:

This is also a one-line JS comment
because JS ignores the closing characters
of HTML-style comments

HTML-style comments are not usually found in the middle of JavaScript code. (The // comments are simpler and easier to read.) However, it is strongly recommended to use HTML comment


Question: How do I hide JS code from old browsers that do not support JavaScript?

Answer: To prevent old browsers from displaying your JS code, do the following:

1. Immediately after the opening

Thus, your HTML file will contain the following fragment:


Old browsers will treat your JS code as one long HTML comment. On the other hand, new JavaScript-aware browsers will normally interpret JS code between the tags (the first and last lines of your JS code will be treated by the JavaScript interpreter as one-line comments).


Question: If the user's browser cannot execute JavaScript code, can I display a warning for the user?

Answer: Yes, you can display a special warning for users of JavaScript-incapable browsers. Put your warning text between the tags . Here's an example:


JavaScript-enabled browsers will ignore everything between . Browsers that cannot execute JavaScript will display your message on the page. NOTE: The

Comments

Popular posts from this blog

How to generate POJO's from Database for HBM or Annotated java beans?

This document will provide steps to reverse engineer POJO’s from Database tables for Hibernate mappings. Step 1 : Open Netbeans IDE and Create Project (Click to enlarge image) Step 2 : Create Hibernate configuration file Provide Database details with dialect Click finish button and it will generate ‘hibernate.cfg.xml’ files. Step 3 : Using Hibernate reverse engineering Wizard create ‘hibernate.reveng.xml’ file Click Next. Select Database tables to generate DAO’s. Click Finish button this will generate ‘hibernate.reveng.xml’ file Step 5 : Create POJO classes. Option One: For HBM mapping file Option Two: For Annotations Click finish button and it will generate POJO (DAO beans) into provided package. Ping me if you need any further help.

Chalata Hai???

I was reading article about logical Indian on Facebook. This very much discussed topic, punctuality of Indians for committed time. It is my experience that we Indian always take 5 to 10 mins liberty for committed appointment. This is part of “chalata hai” attitude. I wish we will able to get rid of such common habit. This also gets reflected in professional work. Software companies follows agile plan daily standup meeting. When senior member makes it mandatory to attend meeting then people somehow try’s (yes people literally tryJ) to come meeting and most of the time 2 to 5 mins late. Then question can we not able manage for 5/10 mins early than planned meeting. When working with other country people, I had experienced they make sure reach 5 to 10 mins before appointment. But we always give excuse about traffic but how come it happens every day and every meeting. It is “Chalata hai” attitude. Same attitude reflected when crossing red light, cutting lane, overtaking and b...

AJax

AJAX = Asynchronous JavaScript and XML AJAX is not a new programming language, but a new technique for creating better, faster, and more interactive web applications. With AJAX, a JavaScript can communicate directly with the server, with the XMLHttpRequest object. With this object, a JavaScript can trade data with a web server, without reloading the page. AJAX uses asynchronous data transfer (HTTP requests) between the browser and the web server, allowing web pages to request small bits of information from the server instead of whole pages. The AJAX technique makes Internet applications smaller, faster and more user-friendly. AJAX is based on Internet standards AJAX is based on the following web standards: JavaScript XML HTML CSS AJAX applications are browser and platform independent. AJAX is about better Internet-applications Internet-applications have many benefits over desktop applications; they can reach a larger audience, they are easier to install and...