判断页面是否是由上一页返回

 1 <input type="hidden" id="history_back" />   
 2 <script>
 3         (function() {
 4             var historyBack = document.getElementById('history_back')
 5             var val = historyBack.value;
 6 
 7             if (val) {
 8           
 9                 setTimeout(function() {
10          
11                     //alert('即将刷新页面');
12                     // window.location.reload(); //重新加载
13                     //window.history.go(-1);//返回上一层
14                 }, 200);
15             } else {
16                 historyBack.value = 'history';
17             }
18             ;
19         }());
20     </script>

 

//原理:第一次进入页面的时候id为history_back的标签为空,会执行第15行的方法为history_back赋值,当页面由下一页返回的时候history_back已经有了值,所以就会跳到第7行的方法里面执行里面的方法

posted @ 2015-07-07 19:52  ordinary01  阅读(3784)  评论(1编辑  收藏  举报