2014-12-02 109 views
0

我剛剛在定義ID屬性(如/name)的計算器上獲得了一些幫助。一些工作後,我得到了我的一個頁面網站使用自定義ID。但!這裏是我的問題:從頁面重定向排除id(jquery)

當訪問者在訪問索引文件,第一次我希望瀏覽器這樣的重定向:

example.com - > 1500後重定向 - > example.com/#/所有/

但是,由於它是單頁網站,因此我的所有其他div(當/all/處於活動狀態時隱藏)都位於同一頁面上,因此具有相同的重定向屬性。因此,如果用戶直接訪問某個ID(example.com/#/work/),瀏覽器將在1500之後重定向到#/all/,因此無法直接鏈接到某些特定項目。另外,我有多個以/work/開頭的ID。

這就是我的工作,現在

window.setTimeout(function() { 

window.location.href = '#/all/'; // redirect the visitor when loading the index for the first time 
}, 1500);  
$('#/work/...','#/about/').on('ready', function() { // Select ALL that has the id "#/about/", and/or all that starts with the id "#/work/" 
    window.location = ""; // No redirect, just load the page with the targeted id active 
}); 
+0

搜索有關會話它可以幫助您。 – 2014-12-02 22:22:08

回答

1

僅僅只運行如果沒有哈希已被定義重定向..

if (window.location.hash.length === 0){ 
    window.setTimeout(function() { 
     window.location.hash = '/all/'; // redirect the visitor when loading the index for the first time 
    }, 1500); 
} 
+0

..就這麼簡單。我想這全是學習曲線。非常感謝你! – QAW 2014-12-02 22:53:27