「test1.html → test2.html → test3.html」の画面遷移の中で
test3.html から test2.htmlにブラウザバックで戻った際に強制的に1回リロードさせるjsです。
なお、<button class="back">Back</button>
で戻った場合にはリロードしないようにしてあります。
test1.html
<button class="next">Next</button>
test2.html
<button class="next">Next</button>
<button class="back">Back</button>
test3.html
<button class="next">Next</button>
<button class="back">Back</button>
js
$(function () {
//test1でnextをクリックする→読み込み済み(loaded)
if(location.pathname=="test1") {
$(".next").click(function(){
window.name = "loaded";
});
}
//test2で未読み込み(null)であればリロード
//test2で読み込み済み(loaded)であればリロードしない
//test2でnextをクリックする→未読み込み(null)
if(location.pathname=="test2") {
if (window.name != "loaded"){
location.reload();
window.name = "loaded";
}
$(".next").click(function(){
window.name = "null";
});
}
//test3でbackをクリックする→読み込み済み(loaded)
//test3でブラウザバックをする→未読み込み(null)
if(location.pathname=="test3") {
$(".back").click(function(){
window.name = "loaded";
});
}
});