Tuesday, 5 March 2013

Easy make java script auto refresh

Hi friends..

In this post i will explain  how can do a refresh a webpage using java script?

Ok lets come..

JAVA SCRIPT : Page Refresh

The webpage to be a reload thats called "Refresh". We make this concept in two ways

1. Refresh page
2. Auto refresh page

You may seen lot of pages they can use auto refresh. ex: yahoo.. cricket.

1.Refresh page:

You can make refresh webpage we can use 'location.reload' method. this method can be called automatically upon an event or simply when the user click the refresh link.

Syntax:

location.reload(true);

Example:


<html>
<head>
<script type="text/javascript">
function refreshPage()
{
location.relaod(true);
}
</script>
<title>Untitled Document</title>
</head>

<body>
<input type="submit" name="submit" value="refresh page" onclick="refreshPage()" />
<br />
<img src="images/images (3).jpg" width="500" height="200" />
<img src="images/images (4).jpg" width="500" height="200"  />
</body>
</html>


or another way


<a href="javascript:location.reload(true")">Refresh</a>

Output is:


2.Auto refresh

Refresh page automatically after the time interval. This may be seen yahoo cricket the scores page automatically refreshed.

Auto refresh make so simple... we already know timing events. we can use time event

Example:


<html>
<head>
<script type="text/javascript">
function refreshPage()
{
alert("a");
setInterval("ref()",5000);
}
function ref()
{
alert("yes");
location.reload(true);
}
</script>

<title>Untitled Document</title>
</head>

<body onload="refreshPage()">

<br />
<img src="images/images (3).jpg" width="500" height="200" /><br />
<img src="images/images (4).jpg" width="500" height="200"  /><br />
<img src="images/images (14).jpg" width="500" height="200"/><br />
<img src="images/tab-cars-img2.jpg"width="500" height="200" /><br />
</body>
</html>

Note: The above example am using alert. this only checking the script are fine or not..


Thanks

No comments:

Post a Comment

What is AI- Artificial Intelligence - தமிழில்

Artificial Intelligence : Artificial intelligence leverages computers and machines to mimic the problem-solving and decision-making capabili...