开发者

jQuery to find URI in codeigniter

I have a script that runs on every page of my codeigniter site.

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

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

I only want that last line setTimeout('changeImage()',9000); if I'm on the base url and there are no segments in the URI (only want this to run on my homepage).

Is this 开发者_Go百科possible to do some type of if statement with jQuery and find out if there are no segments in the URI?

Thanks


Well you can do this with simple javascript using window.location, you have three things to worry about: pathname, search and hash, the code will be something like:

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


use window.location

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜