JavaScript를 사용하여 페이지를 다시로드하는 방법
JavaScript를 사용하여 페이지를 다시로드하려면 어떻게해야합니까?
모든 브라우저에서 작동하는 방법이 필요합니다.
자바 스크립트 1.0
window.location.href = window.location.pathname + window.location.search + window.location.hash;
// creates a history entry
자바 스크립트 1.1
window.location.replace(window.location.pathname + window.location.search + window.location.hash);
// does not create a history entry
자바 스크립트 1.2
window.location.reload(false);
// 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'.
location.reload();
자세한 내용은이 MDN 페이지 를 참조하십시오.
다음은 자바 스크립트를 사용하여 페이지를 다시로드하는 535 가지 방법 , 가장 쉬운 존재는 location = location
.
다음은 처음 50 개입니다.
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)
self.location.replace(location)
location['assign'](location)
location['replace'](location)
window.location['assign'](location)
window.location['replace'](location)
window['location'].assign(location)
window['location'].replace(location)
window['location']['assign'](location)
window['location']['replace'](location)
self.location['assign'](location)
self.location['replace'](location)
self['location'].assign(location)
self['location'].replace(location)
self['location']['assign'](location)
self['location']['replace'](location)
location.href = location
location.href = location.href
location.href = window.location
location.href = self.location
location.href = window.location.href
location.href = self.location.href
location.href = location['href']
location.href = window['location']
location.href = window['location'].href
location.href = window['location']['href']
location.href = window.location['href']
location.href = self['location']
location.href = self['location'].href
location.href = self['location']['href']
location.href = self.location['href']
...
을 사용하여이 작업을 수행 할 수 있습니다 window.location.reload();
. 이를 수행하는 방법은 여러 가지가 있지만 JavaScript로 동일한 문서를 다시로드하는 적절한 방법이라고 생각합니다. 여기에 설명이 있습니다
JavaScript window.location
개체를 사용할 수 있습니다.
- 현재 페이지 주소 (URL) 가져 오기
- 브라우저를 다른 페이지로 리디렉션하려면
- 동일한 페이지를 다시로드하려면
window
: JavaScript에서 브라우저의 열린 창을 나타냅니다.
location
: JavaScript에는 현재 URL에 대한 정보가 있습니다.
The location
object is like a fragment of the window
object and is called up through the window.location
property.
location
object has three methods:
assign()
: used to load a new documentreload()
: used to reload current documentreplace()
: used to replace current document with a new one
So here we need to use reload()
, because it can help us in reloading the same document.
So use it like window.location.reload();
.
To ask your browser to retrieve the page directly from the server not from the cache, you can pass a true
parameter to location.reload()
. This method is compatible with all major browsers, including IE, Chrome, Firefox, Safari, Opera.
Try:
window.location.reload(true);
The parameter set to 'true' reloads a fresh copy from the server. Leaving it out will serve the page from cache.
More information can be found at MSDN and in the Mozilla documentation.
I was looking for some information regarding reloads on pages retrieved with POST requests, such as after submitting a method="post"
form.
To reload the page keeping the POST data, use:
window.location.reload();
To reload the page discarding the POST data (perform a GET request), use:
window.location.href = window.location.href;
Hopefully this can help others looking for the same information.
This works for me:
function refresh() {
setTimeout(function () {
location.reload()
}, 100);
}
http://jsfiddle.net/umerqureshi/znruyzop/
To reload a page using JavaScript, use:
window.location.reload();
If you put
window.location.reload(true);
at the beginning of your page with no other condition qualifying why that code runs, the page will load and then continue to reload itself until you close your browser.
location.href = location.href;
To make it easy and simple, use location.reload()
. You can also use location.reload(true)
if you want to grab something from the server.
Using a button or just put it inside an "a" (anchor) tag:
<input type="button" value="RELOAD" onclick="location.reload();" />
Try these for other needs:
Location Objects has three methods --
assign() Used to load a new document
reload() Used to reloads the current document.
replace() Used to replace the current document with a new one
Automatic reload page after 20 seconds.
<script>
window.onload = function() {
setTimeout(function () {
location.reload()
}, 20000);
};
</script>
Thank you, this post was very helpful, not only to reload the page with the suggested answer, but also as well to give me the idea to place a jQuery UI icon to a button:
<button style="display:block; vertical-align:middle; height:2.82em;"
title="Cargar nuevamente el código fuente sin darle un [Enter] a la dirección en la barra de direcciones"
class="ui-state-active ui-corner-all ui-priority-primary"
onclick="javascript:window.location.reload(true);">
<span style="display:inline-block;" class="ui-icon ui-icon-refresh"></span>
[<b>CARGAR NUEVAMENTE</b>]
</button>
2016-07-02
This should work:
window.location.href = window.location.href.split( '#' )[0];
or
var x = window.location.href;
x = x.split( '#' );
window.location.href = x[0];
I prefer this for the following reasons:
- Removes the part after the #, ensuring the page reloads on browsers that won't reload content that has it.
- It doesn't ask you if want to repost last content if you recently submit a form.
- It should work even on most recent browsers. Tested on Lasted Firefox and Chrome.
Alternatively, you may use the most recent official method for this task
window.location.reload()
Use this button to refresh the page
<input type="button" value="Reload Page" onClick="document.location.reload(true)">
You can simply use
window.location=document.URL
where document.URL gets the current page URL and window.location reloads it.
참고URL : https://stackoverflow.com/questions/3715047/how-to-reload-a-page-using-javascript
'Development Tip' 카테고리의 다른 글
POST와 PUT HTTP REQUEST의 차이점은 무엇입니까? (0) | 2020.09.29 |
---|---|
DateTime 객체가 주어지면 어떻게 ISO 8601 날짜를 문자열 형식으로 얻습니까? (0) | 2020.09.29 |
Node.js 모범 사례 예외 처리 (0) | 2020.09.29 |
충돌이있는 자식 병합을 실행 취소하는 방법 (0) | 2020.09.29 |
두 개의 디렉토리 트리가 주어지면 어떤 파일이 다른지 어떻게 알 수 있습니까? (0) | 2020.09.29 |