Methods of the DOM Location Object - The Jatrix…Reloaded()
(Page 3 of 4 )
I have to confess that when I was coding this next example I decided to see if I could make it super annoying, and sure enough, I could. Reload() is used to reload the current document or page. That being said, you might want to avoid using it with document.write, as I do in this next example. Granted, it's easy enough to get out of the situation (just press control + alt + delete and close your browser window). Behold…Annoying Page 2000:
<html>
<head>
<script type="text/javascript">
document.write(window.location.reload());
</script>
</head>
</html>
Wheee! Okay, learned your lesson yet? Obviously you won’t want to do that to your visitor. Well, some of you will…like the guy with the funny hat. But if you want your visitors to come back, then slap that code into a button and offer it as an option instead of forcing it upon them.
Here is the non-caveman code:
<html>
<head>
<script type="text/javascript">
function optional()
{
window.location.reload();
}
</script>
</head>
<body>
<input type="button" value="Click Here to Reload the Page" onclick="optional()" />
</body>
</html>
When the user clicks on the button, it triggers the optional() function, which reloads the page.
Note that, depending on your browser, you may get a pop-up box like the one seen below:

Next: Replace() >>
More JavaScript Articles
More By James Payne