1

我有一个在我的 codeigniter 站点的每个页面上运行的脚本。

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

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

setTimeout('changeImage()',9000);如果我在基本 url 上并且 URI 中没有段(只希望它在我的主页上运行),我只想要最后一行。

这是否可以if使用 jQuery 执行某种类型的语句并找出 URI 中是否没有段?

谢谢

4

2 回答 2

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
于 2011-04-14T18:38:23.197 回答
1

使用window.location

if ( window.location == YOUR_BASE_URL ) {
    setTimeout('changeImage()',9000);
}
于 2011-04-14T18:11:42.527 回答