Tuesday, October 21, 2014

Basics of Javascript , javascript v/s java ,vbscript, script tag , noscript tag , implementation of javascript

Objects,Properties,Value,Methods:


Objects:
        - A programing function that models the charachteristics of abstract or
Real “object” using classes.
Properties:
        - A descriptive charachteristics of an object.
Value:
        - The specific quality to the property of an object.
Methods:
        - An action that can be performed by an object.

 

Javascript AND Java:

JavaScript

JAVA

Interpreted (not compiled) by client.

Compiled on server before execution on client.

Variable data types not declared (loose typing).

Variable types must be declared
(strong typing ).

Dynamic binding; object references checked at run time.

Static binding; object references must exist at compile time

Secure; cannot write to hard disk.

Secure; cannot write to hard disk

Code integrated with and embedded in HTML.

 

 

JavaScript and VBScript:

  - JavaScript and VBScript are scripting languages that have similar purposes.
Both extend the capabilities of static Web pages.
- JavaScript was the first scripting language developed for Web page design.
- It has been incorporated into Netscape Navigator browsers since version 2.0.
- VBScript is the Microsoft Web-scripting language, based on the powerful and popular      
Visual Basic language.
- JavaScript is a strong object-based language that relies, for much of its functionality,
on objects and their attendant methods and properties.

V        

<SCRIPT> Tag:

  • The HTML <script> tag is used to insert a JavaScript into an HTML page.
  • Inside <script> tag type attribute is used to specify the scripting language.
  • JavaScript can write into two sections between <HEAD> tag or between <BODY> tag.
  • If user writes code in <body> section then JavaScript code will be executed immediately after the page has been load.
  • If user writes code in <head> section then JavaScript code will be executed depends on user’s requirement.

Syntax:
<HTML>
<BODY>
<SCRIPT TYPE = “TEXT/JAVASCRIPT”>
                                     . . . .                                                      
      All JavaScript code will </SCRIPT>                                                                 
</HTML>

Attributes of <SCRIPT> Tag:

1)language:This indicates the scripting language of the code as specifier.

                   EX:<script language=”javascript”>

2)type: This indicates the scripting language of the code as content - type.

                  EX:<script type=”text/javascript”>

3)src:Points to an external resource where the script code is declared.

The <NOSCRIPT> Tag.

  • You should be aware that your users may have older browsers that do not support JavaScript, or may disable execution of JavaScript code within their browsers. If so, you can use the HTML <NOSCRIPT> tag to render content for these users.

Example:
<script type="text/javascript">
<h1>This is a SCRIPT TAG Example</h1>
</script>
<noscript>
<h1>This is a NOSCRIPT TAG Example</h1>
</noscript>

Where to Put the JavaScript?
- JavaScripts in a page will be executed immediately while the page loads into the browser.  
- This is not always what we want. Sometimes we want to execute a script when a page  
loads, other times when a user triggers an event.

 Scripts in the head section: Scripts to be executed when they are called, or when an
event is triggered, go in the head section.
<html>
<head>
<script type="text/javascript">
document.write("Shree Solution Junagadh");
</script>
</head>
</html>

Scripts in the body section: Scripts to be executed when the page loads go in the body
section. When you place a script in the body section it generates the content of the page.
<html>
<head>
<script type="text/javascript">
document.write("Shree Solution Junagadh");
</script>
</head>
</html>

Scripts in both the body and the head section: You can place an unlimited number of
scripts in your document, so you can have scripts in both the body and the head section.
<html>
<head>
<script type="text/javascript">
document.write("Shree Solution Junagadh");
</script>
</head>
<body>
<script type="text/javascript">
document.write("Shree Solution Junagadh");
</script>
</body>

</html>