2011-04-14 62 views
1

我有一個腳本,可以在我的codeigniter站點的每個頁面上運行。jQuery在codeigniter中查找URI

jQuery(document).ready(function($) { 
    Cufon.replace('h1'); 
    $('#term').hint(); 

    setTimeout('changeImage()',9000); 
}); 

我只希望最後一行setTimeout('changeImage()',9000);如果我的基本URL和有在URI沒有段(只希望這在我的主頁上運行)。

這是可能做一些if聲明與jQuery的類型,並找出是否沒有段的URI?

感謝

回答

1

使用window.location

if (window.location == YOUR_BASE_URL) { 
    setTimeout('changeImage()',9000); 
} 
2

那麼你可以使用window.location的簡單的JavaScript做到這一點,你有三件事情擔心:路徑,搜索和散列,代碼將是什麼如:

var win_location = window.location; 
if (win_location.pathname === "" || win_location.pathname === "/" && win_location.hash === "" && win_location.search === "") 
{ 
    // I'M HOME NOW DO SOMETHING 
} 
// hash will be for things like #anchor in the url 
// search will be for things like ?param1=john&param2=doe 
// so if you need those for some kind of dynamic handling on the home page remove the 
// matching condition