programing

뒤로 버튼 클릭 시 페이지를 새로 고치는 방법은 무엇입니까?

linuxpc 2023. 8. 4. 22:42
반응형

뒤로 버튼 클릭 시 페이지를 새로 고치는 방법은 무엇입니까?

.htaccess를 사용하여 모든 트래픽을 단일 index.php 파일로 라우팅합니다.아래 코드는 트래픽을 지시하지만 어떤 이유로 뒤로 단추와 함께 작동하지 않습니다.뒤로 버튼을 작동시키려면 어떻게 해야 할지 모르겠습니다.저는 다양한 것들을 시도해봤고 꽤 많은 것들을 검색해봤지만 아무 것도 효과가 없었기 때문에 여기 있는 누군가가 도와줄 수 있기를 바랍니다!

<?php
   if(isset($_GET['parameters'])) {
      if($_GET['parameters'] == "repair")
         include 'repair.html';
      else if($_GET['parameters'] == "training")
         include 'training.html';
      else if($_GET['parameters'] == "products")
         include 'products.html';
      else if($_GET['parameters'] == "about")
         include 'about.html';
      else if($_GET['parameters'] == "employees")
         include 'employees.html';
      else if($_GET['parameters'] == "training")
         include 'training.html';
      else if($_GET['parameters'] == "newaccount")
         include 'newaccount.html';
      else if($_GET['parameters'] == "contact")
         include 'contact.html';
      else if($_GET['parameters'] == "recommended")
         include 'recommended.html';
      else if($_GET['parameters'] == "careers")
         include 'careers.html';
      else
         include 'home.html';
   }
   else
      include 'home.html';
?>

지금까지 시도했지만 실패했습니다.window.onbeforeunload body onunload=""

할 수 있는 방법이 있어야 합니다.onunload=location.reload()아니면 뭔가!어떻게든 구문을 알아야 합니다!!

해보세요...테스트되지 않은그것이 당신에게 효과가 있기를 바랍니다.

새 php 파일을 만듭니다.페이지의 뒤로 및 앞으로 버튼을 사용하고 숫자/시간 스탬프를 항상 업데이트할 수 있습니다.

<?php
header("Cache-Control: no-store, must-revalidate, max-age=0");
header("Pragma: no-cache");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
echo time();
?>
<a href="http://google.com">aaaaaaaaaaaaa</a>

또는

다른 해결책을 찾았습니다.

사용자가 뒤로 버튼을 누르면 온로드 이벤트가 실행되어야 합니다.JavaScript를 통해 생성되지 않은 요소는 해당 값을 유지합니다.동적으로 생성된 요소에 사용된 데이터의 백업을 INPUT TYPE="숨김" 세트 내에 표시되도록 유지하는 것이 좋습니다. 그런 다음 입력 값을 사용하여 온로드에서 동적 요소를 원래대로 재구축합니다.

<input type="hidden" id="refreshed" value="no">
<script type="text/javascript">
onload=function(){
var e=document.getElementById("refreshed");
if(e.value=="no")e.value="yes";
else{e.value="no";location.reload();}
}

최신 솔루션은 PerformanceNavigation 인터페이스를 사용하는 것입니다.

if(!!window.performance && window.performance.navigation.type === 2)
{
    console.log('Reloading');
    window.location.reload();
}

여기서 값 2는 "이력으로 이동하여 페이지에 액세스했습니다"를 의미합니다.

여기에서 브라우저 지원 보기: http://caniuse.com/ #search=Configuration%20Timing%20API

브라우저를 통해 사이트에 도달하면 다시 로드하기 단추

Safari에서 숨겨진 입력 솔루션이 작동하지 않았습니다.아래 솔루션은 작동하며 여기에서 제공되었습니다.

window.onpageshow = function(event) {
if (event.persisted) {
    window.location.reload() 
}
};

저는 이 일을 처리하는 두 가지 방법을 찾았습니다.당신의 경우에 가장 적합한 것을 고르세요.Firefox 53 및 Safari 10.1에서 테스트된 솔루션

사용자가 뒤로/앞으로 단추를 사용하고 있는지 탐지한 다음 전체 페이지 다시 로드

if (!!window.performance && window.performance.navigation.type === 2) {
            // value 2 means "The page was accessed by navigating into the history"
            console.log('Reloading');
            window.location.reload(); // reload whole page

        }

페이지가 캐시된 경우 전체 페이지 다시 로드

window.onpageshow = function (event) {
        if (event.persisted) {
            window.location.reload();
        }
    };

여기에 게시된 이 간단한 솔루션 뒤로 페이지 강제 새로 고침 버튼이 작동했습니다...

사용자가 뒤로 버튼을 클릭하면 브라우저에서 페이지를 다시 다운로드하려고 했지만 아무 것도 작동하지 않았습니다.현대의 브라우저는 페이지에 대한 별도의 캐시가 있어 페이지의 전체 상태(자바스크립트 생성 DOM 요소 포함)를 저장하므로 사용자가 뒤로 버튼을 누르면 이전 페이지가 사용자가 떠난 상태로 즉시 표시됩니다.브라우저가 페이지를 뒤로 다시 로드하도록 하려면 unload="를 (X)에 추가합니다.HTML 본문 요소:

<body onunload="">

이렇게 하면 특수 캐시가 비활성화되고 사용자가 뒤로 단추를 누를 때 페이지가 강제로 다시 로드됩니다.그것을 사용하기 전에 두 번 생각해 보세요.이러한 솔루션이 필요하다는 사실은 사이트 탐색 개념에 결함이 있다는 것을 암시합니다.

당신은 이런 것을 시도했습니까?테스트되지 않음...

$(document).ready(function(){
    $('.ajaxAnchor').on('click', function (event){ 
        event.preventDefault(); 
        var url = $(this).attr('href');
        $.get(url, function(data) {
            $('section.center').html(data);
            var shortened = url.substring(0,url.length - 5);
            window.location.hash = shortened;
        });
    });
});

다음을 사용하여 뒤로 단추를 눌러 페이지를 새로 고칠 수 있습니다.

window.addEventListener('popstate', () => {
  location.reload();
}, false);

코드의 모든 삽입 필드:

<input id="reloadValue" type="hidden" name="reloadValue" value="" />

그런 다음 jQuery를 실행합니다.

<script type="text/javascript">
   jQuery(document).ready(function()
    {
            var d = new Date();
            d = d.getTime();
            if (jQuery('#reloadValue').val().length === 0)
            {
                    jQuery('#reloadValue').val(d);
                    jQuery('body').show();
            }
            else
            {
                    jQuery('#reloadValue').val('');
                    location.reload();
            }
    });

window.onbeforeunload = function() { redirect(window.history.back(1)); };

아헤무_u

뒤로 단추는 우리 모두에게 어떤 곳에서는 고통이라고 말했듯...그러니까...

페이지를 정상적으로 로드하는 한 많은 문제가 발생합니다.표준 "사이트"의 경우 그렇게 많이 바뀌지는 않을 것입니다.하지만 저는 당신이 이런 것을 만들 수 있다고 생각합니다.

사용자는 로드할 항목을 선택하는 페이지 .php에 매번 액세스합니다.페이지를 캐시하지 않기 위해 캐시 작업을 조금 시도할 수 있으며 만료 날짜가 될 수도 있습니다.

그러나 장기 솔루션은 "onload" 이벤트에 코드를 넣어 데이터를 가져온 Ajax를 가져올 것입니다. 이 방법으로 (자바스크립트를 사용하여) 원하는 코드를 실행하고 페이지를 새로 고칠 수 있습니다.

언급URL : https://stackoverflow.com/questions/20899274/how-to-refresh-page-on-back-button-click

반응형