Programing

jQuery를 사용하여 페이지를 한 번 새로 고침 (다시로드) 하시겠습니까?

lottogame 2020. 10. 7. 07:11
반응형

jQuery를 사용하여 페이지를 한 번 새로 고침 (다시로드) 하시겠습니까?


jQuery를 사용하여 페이지 (또는 특정 div)를 한 번 (!) 새로 고침 / 다시로드하는 방법이 궁금합니다.

이상적으로 DOM structure는 사용 가능 ( onload이벤트 참조 ) 직후에 부정적인 영향 back button이나 bookmark기능에 영향을주지 않는 방식 입니다.

참고 : replace()타사 제한으로 인해 허용되지 않습니다.


좋아, 나는 당신이 요구하는 것을 얻은 것 같습니다. 이 시도

if(window.top==window) {
    // You're not in a frame, so you reload the site.
    window.setTimeout('location.reload()', 3000); //Reloads after three seconds
}
else {
    //You're inside a frame, so you stop reloading.
}

한 번이면 그냥 해

$('#div-id').triggerevent(function(){
    $('#div-id').html(newContent);
});

주기적으로

function updateDiv(){
    //Get new content through Ajax
    ...
    $('#div-id').html(newContent);
}

setInterval(updateDiv, 5000); // That's five seconds

따라서 5 초마다 div # div-id 콘텐츠가 새로 고쳐집니다. 전체 페이지를 새로 고치는 것보다 낫습니다.


다시로드하려면 다음을 시도하십시오.

window.location.reload(true);

window.location.href=window.location.href;

$('#div-id').click(function(){

   location.reload();
        });

이것은 올바른 구문입니다.

$('#div-id').html(newContent); //This doesnt work

이것을 사용하십시오 :

    <script type="text/javascript">
        $(document).ready(function(){

            // Check if the current URL contains '#'
            if(document.URL.indexOf("#")==-1)
            {
                // Set the URL to whatever it was plus "#".
                url = document.URL+"#";
                location = "#";

                //Reload the page
                 location.reload(true);
            }
        });
    </script>

if조건 으로 인해 페이지는 한 번만 새로 고침됩니다.


이것은 JavaScript 기본이기 때문에 jQuery 새로 고침 기능이 없습니다.

이 시도:

<body onload="if (location.href.indexOf('reload')==-1) location.replace(location.href+'?reload');">

사용하다:

<html>
    <head>
        <title>Reload (Refresh) Page Using Jquery</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $('#reload').click(function() {
                    window.location.reload();
                });
            });
        </script>
    </head>
    <body>
        <button id="reload" >Reload (Refresh) Page Using</button>
    </body>
</html>

Add this to the top of your file and the site will refresh every 30 seconds.

<script type="text/javascript">
    window.onload = Refresh;

    function Refresh() {
        setTimeout("refreshPage();", 30000);
    }
    function refreshPage() {
        window.location = location.href;
    }
</script>

Another one is: Add in the head tag

<meta http-equiv="refresh" content="30">

 - 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']

You don't need jQuery for this. You can do it with JavaScript.


Use this instead

function timedRefresh(timeoutPeriod) {
    setTimeout("location.reload(true);",timeoutPeriod);
}

<a href="javascript:timedRefresh(2000)">image</a>

Try this code:

$('#iframe').attr('src', $('#iframe').attr('src'));

Try this:

<input type="button" value="Reload" onClick="history.go(0)">

For refreshing page with javascript, you can simply use:

location.reload();

You may need to use this reference along with location.reload() check this, it will work.

this.location.reload();

참고URL : https://stackoverflow.com/questions/2557480/refresh-reload-a-page-once-using-jquery

반응형