Showing posts with label JAVASCRIPT. Show all posts
Showing posts with label JAVASCRIPT. Show all posts

How do I enable JavaScript in my browser?

How do I enable JavaScript in my browser?

In order to view Google ads on a website, you will need to have JavaScript enabled in your browser. To do so, please follow the instructions below:

Internet Explorer (6.0)

  1. Select 'Tools' from the top menu

  2. Choose 'Internet Options'

  3. Click on the 'Security' tab

  4. Click on 'Custom Level'

  5. Scroll down until you see section labled 'Scripting'

  6. Under 'Active Scripting', select 'Enable' and click OK

Netscape Navigator (4.8)

  1. Select 'Edit' from the top menu

  2. Choose 'Preferences'

  3. Choose 'Advanced'

  4. Choose 'Scripts & Plugins'

  5. Select the 'Enable JavaScript' checkbox and click OK

Mozilla Firefox (1.0)

  1. Select 'Tools' from the top menu

  2. Choose 'Options'

  3. Choose 'Web Features' from the left navigation

  4. Select the checkbox next to 'Enable JavaScript' and click OK

Mozilla Firefox (1.5)

  1. Select 'Tools' from the top menu

  2. Choose 'Options'

  3. Choose 'Content' from the top navigation

  4. Select the checkbox next to 'Enable JavaScript' and click OK

Apple Safari (1.0)

  1. Select 'Safari' from the top menu

  2. Choose 'Preferences'

  3. Choose 'Security'

  4. Select the checkbox next to 'Enable JavaScript'

Using cookies in JavaScript

Using cookies


This JavaScript example places one item from a set of items (tips, thoughts, quotes, banners)
on your Web page. It simply includes in your page one string from a big array.
Since the strings may be long and may contain any HTML tags, you can easily create,
for example, banner rotation.


Each time the page loads, a new item will be displayed.
Every visitor has his own counter stored in a browser cookie.



<html>

<body>



<script type="text/javascript">


<!--

var count=document.cookie.indexOf("cnt=");

if(count>=0) count=document.cookie.substring(count+4);

else count=0;

document.cookie = "cnt=" + (count+1) + ";expires=Fri,1 Jan 2010 00:00:00";

var aStrings = new Array(

"<a href='index.html'>Home Page</a>",


"<a href='examples.html'>JavaScript Examples</a>",

"<a href='tutorials.html'>JavaScript Tutorials</a>"

);

document.write(aStrings[count%aStrings.length]);

//-->


</script>



</body>

</html>

This script uses a cookie (a small file that gets written onto your hard disk by JavaScript
from the Web site you're visiting) to store the variable count.
This variable is incremented every time the page is loaded, and is used as an index of the
array aStrings, which contains HTML strings.

Image swapping using JavaScript

Image swapping


Here's the classic mouseover button effect that shows one image when it's left alone,
and another when the mouse passes over it...



<html>

<head>

</head>

<script type="text/javascript">


<!--

function PreloadImages() {

var aImages = new Array('img12.jpg','img22.jpg');

for(var i=0; i < aImages.length; i++) {

var img = new Image();

img.src = aImages[i];

}

}


//-->

</script>

<body onLoad="PreloadImages()">



<a href="index.html"

onMouseOver="document.img1.src='img12.jpg';"

onMouseOut="document.img1.src='img11.jpg';">

<img src="img11.jpg" name="img1">




<a href="javascript-examples.html"

onMouseOver="document.img2.src='img22.jpg';"

onMouseOut="document.img2.src='img21.jpg';">

<img src="img21.jpg" name="img2">



</body>

</html>

In the above JavaScript example there are two graphic buttons, one called "img11.jpg" and the other called "img21.jpg." The buttons contain onMouseOver and onMouseOut instructions that change the image objects from "img11.jpg" to "img12.jpg" and from "img21.jpg" to "img22.jpg" respectively, and back again.

The body tag has an event handler called onLoad, which calls the function PreloadImages once a page finishes loading. This function creates an array of the names of images to preload, and then creates a new Image object for each name.

This makes the browser to preload all images and store them in the cache when the page first loads, before any rollover action. It's necessary for instant image swapping

Drawbacks of JavaScript

The drawbacks of JavaScript

Right now the biggest problem is the imperfect JavaScript implementations that today's browsers offer. Although all major browsers that are version 3.0 or higher include JavaScript support, they deal with JavaScript differently.

In fact, different versions of the same browser handle JavaScript differently. This makes it difficult to create a complicated JavaScript code that work across all browsers. So always check your pages on as many different browsers (and even platforms) as possible.

JavaScript code that prints current date in the top right corner of your Web page

JavaScript code that prints current date in the top right corner
of your Web page...



<html>

<head>

<script type="text/javascript">

<!--

function PrintDate() {


today = new Date();

document.write('Date: ', today.getMonth()+1, '/', today.getDate(), '/', today.getYear());

}

//-->

</script>

</head>



<body>

<p align="right">


<script type="text/javascript">

<!--

PrintDate();

//-->

</script>

</p>

THE REST OF YOUR PAGE.

</body>

</html>

Simple JavaScript code

What do JavaScript code look like?


Like HTML, JavaScript is just text that can be typed into a text editor. Its code is embedded
in HTML within a <SCRIPT> tag. Some old browsers don't understand this tag.
To prevent them from treating your JavaScript as HTML, always use this trick involving HTML comments...



<script type="text/javascript">

<!-- hide JavaScript code from old browsers

YOUR SCRIPT HERE


// end the hiding comment -->

</script>

List of the common event handlers in java script



























EventWhen it's triggered
onAbortAn image is stopped from loading because the user either hits Stop or leaves the page.
onBlurAn element, such as a window, frame, or form field, loses focus; that is, when the user clicks on something else.
onClickThe user clicks on the particular element.
onChangeThe value of a form field changes, for example, when the user types in some data.
onDblClickThe user double-clicks on the particular element.
onErrorA loading error happens, like a missing image.
onFocusThe user puts the focus on the target element, by clicking on it or tabbing to it.
onKeyDownA key on the keyboard is pushed down, regardless of whether it's then held down or released.
onKeyPressThis event is repeatedly triggered as long as a key is held down.
onKeyUpA key on the keyboard is released.
onLoadThe browser completely loads the page.
onMouseDownA key on the mouse is pushed down, regardless of whether it's then held down or released.
onMouseMoveThe mouse moves.
onMouseOutThe pointer moves out of the target area.
onMouseOverThe pointer moves over the target element.
onMouseUpA key on the mouse is released.
onResetThe Reset button of a form is clicked.
onResizeA window or frame is resized by the user.
onSelectThe user highlights text in a form field.
onSubmitA form is submitted.
onUnloadThe user leaves the page.

What is JavaScript?

What is JavaScript?

JavaScript is a compact, object-based scripting language for Web pages. JavaScript code embedded into your HTML pages can enhance them with many interesting elements, from swapping images when you move a cursor over them, to multi-level drop-down menus.

You can create really sophisticated and almost application-like pages with the help of JavaScript. You don't need any special software other than a text editor and a Web browser, and you don't need access to a Web server. You can create and test all your JavaScript code right on your own computer.