2011-04-14 58 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