programing

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

css3 2023. 10. 7. 12:06

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

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

이상적으로 그 직후에DOM structure사용 가능합니다(cf).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;

사용 방법:

    <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조건, 페이지가 한 번만 다시 로드됩니다.

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

   location.reload();
        });

이것이 정확한 구문입니다.

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

jQuery refresh 기능이 없습니다. 자바스크립트 기본이기 때문입니다.

시도해 보기:

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

파일 상단에 추가하면 사이트가 30초마다 새로 고쳐집니다.

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

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

또 하나는 헤드태그에 추가하기

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

이거는 jQuery 필요 없어요.자바스크립트로 할 수 있습니다.

대신 사용

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

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

다음 코드를 사용해 보십시오.

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

시도해 보기:

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

javascript로 페이지를 새로 고치면 간단히 다음을 사용할 수 있습니다.

location.reload();

사용해야 할 수도 있습니다.this와 함께 참조location.reload()이것 좀 확인해봐요, 잘 될 겁니다.

this.location.reload();

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