Wednesday, May 19, 2010

Create a web page becomes "live"

JavaScript is a scripting language (scripting language) developed by Netscape Corp.., And are intended to enhance the features of a webpage. With the existence of a web page JavaScript will become more dynamic and interactive to the user, because the web pages to function as an application program that can process the input provided by the user and gives results in accordance with its programmed. Web page that is the answer to a user request should not be downloaded from the web server first, but generated by the JavaScript that is on the browser.

Lots of web pages on the Internet that has implemented a JavaScript, such as Netscape (http://home.netscape.com), see PowerStart application that allows us to interact on one of his web pages.

Differences in the workings of ordinary web pages to web pages with JavaScript penjawaban in terms of user input can be seen in the image below:






Figure 2 : Interaction of web pages that have JavaScript by server. Page 2 is a web page has JavaScript.


JavaScript is a result of the work process above, then the server load will be lighter, and web pages will be much quicker to respond even at the lowest internet connection though.

In practice, the JavaScript is included in web pages and as web pages are opened by the user, the Netscape browser will meninterpretasi (interpret) the lines of existing scripts and execute scripts in accordance with the commands listed.

At first glance JavaScript similar to the Java language, but they have fundamental differences. Comparison of the two is as follows:


JavaScript
Interpreted by the browser
Dynamic binding
The script is limited by browser
Runing together with HTML
Objects can access the browser and become functional.


Java
Di-compile and placed on the server, run in a browser.
Static binding
capabilities stand-alone application
more than HTML, like as multimedia
can`t access with object browser

JavaScript applications
Some examples of applications are usually implemented with JavaScript:
  • Calculator; with JavaScript enabled web page that displays a calculator if you have downloaded can work without having to interact more with the web server
  • Display time; with JavaScript can display a web page clock, date, etc.
  • Feedback status
  • Users can track the status of a process
  • Verification form; before the form that has been filled by the user is sent to the server, JavaScript can verify the truth in advance, without having to communicate with the server.
  • Entertainment; web pages can be used as a means of interactive games without burdening the network traffic and server
  • Changing the color of the browser, because JavaScript can access all the objects that exist in your browser, then the color composition of a web page can be changed according to tastes in real time.
  • Changing a link;
  • Reformat the page
  • Analysis tools
  • Dialog boxes for warnings (alerts), confirmation, and prompt (waited for input from the user)
  • Window customize
  • Window Navigation


The structure of JavaScript in web pages
JavaScript language structures that are included in a web page is as follows:

<HTML>
<HEAD>
.. heading (title, etc) ..

<SCRIPT LANGUAGE=”JavaScript”>
<!--
..
declaration of variabel, object, dan function JavaScript
..
<!-- end script -- >
</SCRIPT>

</HEAD>

<BODY>
..
declaration of variabel, object, dan function JavaScript
..
</BODY>
</HTML>



In the structure above we can see that to add the JavaScript program on a Web page is to add a tag </SCRIPT>., then comment tag (<!--), pendeklarasian variables and all functions are used, ending with a comment tag again (<!-- and - ->), and closes with the tag </SCRIPT>..


JavaScript language itself is a language that is object-oriented, where we can create an instance of an object or function, or create a new object or function of the object-obejct that has been available (built-in object).

function (arg1, arg2, …) {
/* deklarasi local variable */
var local_variable1 = 0;
var local_variable2 = arg2;

/* deklarasi program */


JavaScript and event web browser
  • JavaScript is working with web pages based on "listening" all the events that occurred between the user with a web browser. Event is an "incident" caused by user interaction with a web browser. Some of them are:
  • onClick: events that occur on an object if the user to click on that object with mouse button
  • onLoad: events that occur when a user to load a web page on your browser
  • onSubmit: events that occur when a user presses the submit button that is in the form of a web page
  • onMouseOver: events that occur on an object if the user moves the mouse across the object
  • onBlur: events that happen on a user object if the mouse leaves the object

Every event that occurs can be attributed to a JavaScript function that causes the function that works and produces the desired output. For example, if we want a submit button of a form on a web page issue a message if the-click, then the script should we include in these web pages are:

<HTML>
<HEAD>
<TITLE>Test JavaScript</TITLE>

<SCRIPT LANGUAGE="JavaScript">
<!--
function OpenMessage() {
alert("Congrate, You are finished making JavaScript");
}
<!-- end script -->

</SCRIPT>
</HEAD>

<BODY>
<FORM>
<INPUT TYPE="submit" NAME="tombol" VALUE="PreesMe"
onClick="OpenMessage()">
</FORM>
</BODY>
</HTML>


In the listing on the note line 6 and line 13, where if the button is pressed at line 13, the button will generate onClick event, which must execute the functions defined OpenMessage ().

OpenMessage() function command to remove the window system (alerts at line 6) which contains the message "Congratulations, you've managed to create a JavaScript".

Results from a simple JavaScript program above is as follows:







To create a script, no special tools needed development, but merely a text editor such as Notepad, Writepad, vi, pico, and so forth. Once finished creating the scripts, a web page that has accompanied the script can be run directly on the Netscape Browser version 2.0 and above.
Create a web page becomes "live"
4/ 5
Oleh

Berlangganan via email

Suka dengan postingan di atas? Silakan berlangganan postingan terbaru langsung via email.