1. 程式人生 > >js判斷用戶是輸入的地址請求的路徑

js判斷用戶是輸入的地址請求的路徑

用戶 class 地址 reload random chrom agen bsp 刷新

 1 /**
 2      * 如果是直接輸入url訪問的則刷新頁面(防止緩存頁面)針對Chrome,其他瀏覽器刷新referrer始終會為空,所以給個隨機路徑訪問就加載不到緩存了。
 3      */
 4     var userAgent = navigator.userAgent; // 獲得瀏覽器的userAgent字符串
 5     if(userAgent.indexOf("Chrome") > -1) {
 6         if(document.referrer == "") {
 7             document.location.reload();
8 } 9 } else { 10 if(document.referrer == "") { 11 document.location.replace(document.location.pathname + "?input=" + Math.random()); 12 } 13 }

js判斷用戶是輸入的地址請求的路徑