<html> <head> <title>jQuery Refresh page example</title> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $('#myButton').click(function() { location.reload(); }); }); </script> </head> <body> <input id="myButton" type="button" value="Click here to Refresh the Page" /> </body> </html>
How to refresh a page at regular intervals in jQuery
To refresh a page at regular intervals you can use setInterval() method along with the location.reload(). Source code for a sample HTML page that will refresh every 5 seconds.
<html> <head> <title>jQuery Refresh page example</title> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { setInterval("location.reload();", 5000); $("#someInfo").html("Time is " + new Date()); }); </script> </head> <body> <p>This page will Refresh every 5 seconds!</p> <div id="someInfo"></div> </body> </html>
No comments:
Post a Comment
NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.