sitelink1 | http://www.grizzlyweb.com/webmaster/javascripts/refresh.asp |
---|---|
sitelink2 | |
sitelink3 | |
sitelink4 | http://1 |
extra_vars4 | ko |
extra_vars5 | ko |
extra_vars6 | sitelink1 |
There are times when the web-author would like their web-page to automatically refresh (or reload) at specified intervals. This is often useful when the page contains time sensitive information. We discuss three versions:
JavaScript RefreshThe preferred page refresh/reload method uses a JavaScript technique that will replace the current page with each refresh in the visitor's page history. This version uses an under-utilized method of dealing with cross browser and old version browser compatibility. It defines multiple JavaScript code blocks, where each JavaScript version block redefines the same function. Only the last version block that is supported by the browser will be used. So older browsers will use the "JavaScript" block, while later browsers will use either the "JavaScript1.1" or "JavaScript1.2" block depending upon the browser's capabilities. If the browser does not support JavaScript or has it disabled, the "noscript" block will be used. We do use the "refresh" meta-tag as a backup method to the JavaScript. |
<html> <head> <title>Refresh JavaScript Example</title> <noscript> <!-- We have the "refresh" meta-tag in case the user's browser does not correctly support JavaScript or has JavaScript disabled. Notice that this is nested within a "noscript" block. --> <meta http-equiv="refresh" content="2"> </noscript> <script language="JavaScript"> <!-- var sURL = unescape(window.location.pathname); function doLoad() { // the timeout value should be the same as in the "refresh" meta-tag setTimeout( "refresh()", 2*1000 ); } function refresh() { // This version of the refresh function will cause a new // entry in the visitor's history. It is provided for // those browsers that only support JavaScript 1.0. // window.location.href = sURL; } //--> </script> <script language="JavaScript1.1"> <!-- function refresh() { // This version does NOT cause an entry in the browser's // page view history. Most browsers will always retrieve // the document from the web-server whether it is already // in the browsers page-cache or not. // window.location.replace( sURL ); } //--> </script> <script language="JavaScript1.2"> <!-- function refresh() { // This version of the refresh function will be invoked // for browsers that support JavaScript version 1.2 // // The argument to the location.reload function determines // if the browser should retrieve the document from the // web-server. In our example all we need to do is cause // the JavaScript block in the document body to be // re-evaluated. If we needed to pull the document from // the web-server again (such as where the document contents // change dynamically) we would pass the argument as 'true'. // window.location.reload( false ); } //--> </script> </head> <!-- Use the "onload" event to start the refresh process. --> <body onload="doLoad()"> <script language="JavaScript"> <!-- // we put this here so we can see something change document.write('<b>' + (new Date).toLocaleString() + '</b>'); //--> </script> </body> </html> |
<html> <head> <title>Refresh Button Example</title> <script language="JavaScript"> <!-- // The "refresh" function implementations are identical // to our regular "JavaScript-Refresh" example. The only // difference from our JavaScript Refresh example is // we do not have a doLoad function that starts our // refresh timer (since we use a refresh button). var sURL = unescape(window.location.pathname); function refresh() { window.location.href = sURL; } //--> </script> <script language="JavaScript1.1"> <!-- function refresh() { window.location.replace( sURL ); } //--> </script> <script language="JavaScript1.2"> <!-- function refresh() { window.location.reload( false ); } //--> </script> </head> <body> <script language="JavaScript"> <!-- // we put this here so we can see something change document.write('<b>' + (new Date).toLocaleString() + '</b>'); //--> </script> <!-- In every example that we use below, we simply call the "refresh" JavaScript function. Our first example uses a "link" that invokes the JavaScript function. --> <p><a href="javascript:refresh(">Refresh Link</a></p> <!-- The "image" button is nothing more than an image nested in a link. --> <p><a href="javascript:refresh("><img src="images/button_green.gif" border="0" align="middle" width="71" height="70"></a>image as a button</p> <!-- The last method ties into the "onclick" event for a form button. --> <form method="GET" action="refreshbutton.htm"> <p><input type="button" onclick="refresh()" value="Refresh Form Button" name="button1"></p> </form> </body> </html> |
"refresh" meta-tagThe biggest problem with the "refresh" meta-tag method of page-refresh is that it can add to the visitor's page-history on various versions of browsers. This means that for each automatic page refresh/reload your site visitor must select the browser's back button. This potentially can be a considerable bother to your visitors as well as a confusion. The preferred refresh method is "JavaScript Refresh" |
<head> <!-- The "refresh" meta-tag's content identifies the number of seconds to delay before refreshing the current document. Notice that the URL tag is not specified, indicating that the current document will be refreshed. --> <meta http-equiv="refresh" content="2"> </head> |
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
» | Page Refresh/Reload | 황제낙엽 | 2007.08.24 | 517 |
25 | Javascript 내장객체 String | 황제낙엽 | 2007.04.10 | 630 |
24 |
유용한 자바스크립트 예제 몇가지 (Tree 및...)
![]() | 황제낙엽 | 2005.10.20 | 423 |
23 | 자바 스크립트 플러그인 | 황제낙엽 | 2005.11.22 | 401 |
22 |
JAVASCRIPT REFERENCE 파일
![]() | 황제낙엽 | 2005.11.22 | 435 |
21 |
JAVASCRIPT Debuger 프로그램
![]() | 황제낙엽 | 2005.11.22 | 320 |
20 |
SelectBox 밑에 CheckBox가 포함된 리스트 만들기
![]() | 황제낙엽 | 2007.01.16 | 841 |
19 | 3시간 걸려서 만든 입력폼 자릿수체크 스크립트 | 황제낙엽 | 2006.04.22 | 415 |
18 | innerHTML | 황제낙엽 | 2005.12.19 | 465 |
17 | insertAdjacentHTML Method | 황제낙엽 | 2005.12.19 | 570 |
16 | 폼으로 XML 데이터 전송 (JSP+Javascript) | 황제낙엽 | 2005.12.04 | 442 |
15 | Methods and properties of Microsoft.XMLDOM | 황제낙엽 | 2005.12.04 | 406 |
14 | 슬라이딩 메뉴 | 황제낙엽 | 2005.12.02 | 466 |
13 | XML+JS 연동 다중셀렉트박스 (1) - <font color="brown">(MS Explorer 전용)</brown> | 황제낙엽 | 2005.12.02 | 369 |
12 | 풍선 도움말 | 황제낙엽 | 2005.11.24 | 310 |
11 | 소스 보기 막기 | 황제낙엽 | 2005.11.18 | 513 |
10 | 카페의 회람 . 막기 소스 | 황제낙엽 | 2005.10.21 | 218 |
9 | 브라우저에서 뒤로 가기 막기와 펑션키(function key) 막기 | 황제낙엽 | 2005.10.21 | 554 |
8 | 아이디 생성 조건 검사 자바스크립트 모듈 | 황제낙엽 | 2004.11.18 | 459 |
7 | 마우스 오버시 살짝 뒤로 물러나는 듯한 링크 -_-;; | 황제낙엽 | 2003.01.04 | 443 |