2016-06-22 2 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

をdocument.readyを実行し、それがどのリフレッシュ/リロードなし#でURLをappedますよりますロードします。ここにこれのコードがあります。

$(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> 
関連する問題