2016-06-22 5 views
0
<script type="text/javascript"> 
    $(document).ready(function() { 

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

      //Reload the page 
      location.reload(true); 

     } 
    }); 
</script> 

위 코드가 작동하지 않습니다. 무엇이 문제입니까?웹 페이지 새로 고침/새로 고침

+2

가능한 복제 [내가 jQuery로 페이지를 새로 고칠 수 있는가? (http://stackoverflow.com/questions/5404839/how-can-i-refresh-a-page-with-jquery) – Timothy

+1

콘솔에 오류가 있습니까? – GolezTrol

+0

받고있는 오류 메시지를 제공해주십시오. –

답변

1

은 어떤 새로 고침/다시로드하지 않고 #과 URL을 apped 것보다 document.ready 실행 것이다로드합니다. 여기에 대한 코드가 있습니다.

$(document).ready(function() { 

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

      //Reload the page 
      window.location.href = window.location.href; 

     } 
    }); 

희망이 있습니다.

0

설정 document.URL은 브라우저 주소 표시 줄의 URL을 변경하지 않습니다. 대신 location.href를 사용하여 페이지에서

location.href = location.href + '#'; 
0

시도해야합니다. 이 코드는 잘 작동합니다.

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

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

      //Reload the page 
      window.location.reload(true); 

     } 
    }); 
</script>