Programing

JavaScript 또는 HTML을 사용하여 페이지 새로 고침

lottogame 2020. 4. 29. 08:07
반응형

JavaScript 또는 HTML을 사용하여 페이지 새로 고침


이 질문에는 이미 답변이 있습니다.

JavaScript 또는 HTML을 사용하여 페이지를 새로 고치는 방법은 무엇입니까?


window.location.reload(); JavaScript로

<meta http-equiv="refresh" content="1">HTML로 (여기서 1= 1 초)


자바 스크립트를 사용하여 페이지 를 다시로드 하는 535 가지 방법 은 다음과 같습니다 .

처음 20 개는 다음과 같습니다.

location = location
location = location.href
location = window.location
location = self.location
location = window.location.href
location = self.location.href
location = location['href']
location = window['location']
location = window['location'].href
location = window['location']['href']
location = window.location['href']
location = self['location']
location = self['location'].href
location = self['location']['href']
location = self.location['href']
location.assign(location)
location.replace(location)
window.location.assign(location)
window.location.replace(location)
self.location.assign(location)

그리고 마지막 10 :

self['location']['replace'](self.location['href'])
location.reload()
location['reload']()
window.location.reload()
window['location'].reload()
window.location['reload']()
window['location']['reload']()
self.location.reload()
self['location'].reload()
self.location['reload']()
self['location']['reload']()

원본 기사


단순히 ..

location.reload(true/false);

false 인 경우 페이지는 캐시에서 또는 서버에서 다시로드됩니다.


window.location.reload()

작동하지만 다음과 같은 다양한 옵션이 있습니다.

window.location.href=window.location.href

당신은 또한 사용할 수 있습니다

<input type="button" value = "Refresh" onclick="history.go(0)" />

그것은 나를 위해 잘 작동합니다.


사용하다:

window.location.reload();

캐시 된 페이지의 업데이트를 제어 할 수있는 작업이 있다면이를 수행하는 좋은 방법이 있습니다.

  • 로드시 항상 페이지의 버전 번호를 문자열 (ajax)로 가져 오는 일부 자바 스크립트를 페이지에 추가하십시오. 예를 들면 다음과 같습니다.www.yoursite.com/page/about?getVer=1&__[date]
  • Compare it to the stored versionnumber (stored in cookie or localStorage) if user has visited the page once, otherwise store it directly.
  • If version is not the same as local version, refresh the page using window.location.reload(true)
  • You will see any changes made on the page.

This method requires at least one request even when no request is needed because it already exists in the local browser cache. But the overhead is less comparing to using no cache at all (to be sure the page will show the right updated content). This requires just a few bytes for each page request instead of all content for each page.

IMPORTANT: The version info request must be implemented on your server otherwise it will return the whole page.

Example of version string returned by www.yoursite.com/page/about?getVer=1&__[date]: skg2pl-v8kqb

To give you an example in code, here is a part of my library (I don't think you can use it but maybe it gives you some idea how to do it):

o.gCheckDocVersion = function() // Because of the hard caching method, check document for changes with ajax 
{
  var sUrl = o.getQuerylessUrl(window.location.href),
      sDocVer = o.gGetData( sUrl, false );

  o.ajaxRequest({ url:sUrl+'?getVer=1&'+o.uniqueId(), cache:0, dataType:'text' }, 
                function(sVer)
                {
                   if( typeof sVer == 'string' && sVer.length )
                   {
                     var bReload = (( typeof sDocVer == 'string' ) && sDocVer != sVer );
                     if( bReload || !sDocVer )
                      { 
                        o.gSetData( sUrl, sVer ); 
                        sDocVer = o.gGetData( sUrl, false );
                        if( bReload && ( typeof sDocVer != 'string' || sDocVer != sVer ))
                         { bReload = false; }
                      }
                     if( bReload )
                      {  // Hard refresh page contents
                        window.location.reload(true); }
                   }
                }, false, false );
};

If you are using version independent resources like javascript or css files, add versionnumbers (implemented with a url rewrite and not with a query because they mostly won't be cached). For example: www.yoursite.com/ver-01/about.js

For me, this method is working great, maybe it can help you too.


try this working fine

jQuery("body").load(window.location.href);

참고URL : https://stackoverflow.com/questions/5294842/refresh-a-page-using-javascript-or-html

반응형