2011-04-14 2 views
1

내 codeigniter 사이트의 모든 페이지에서 실행되는 스크립트가 있습니다.codeigniter에서 URI를 찾을 수있는 jQuery

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

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

나는 단지 내가 기본 URL에있어와 URI에는 세그먼트가없는 경우 마지막 줄 setTimeout('changeImage()',9000);가 (만이 내 홈페이지에 실행하려는) 것을 원한다.

어떤 유형의 if 문을 jQuery와 함께 수행 할 수 있으며 URI에 세그먼트가 없는지 확인하십시오.

감사

답변

1

사용 window.location

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

그럼 당신은 간단한 자바 스크립트에서는 window.location을 사용하여이 작업을 수행 할 수 있습니다, 당신이 걱정하는 세 가지가 있습니다, 경로 검색 및 해시 코드가 될 것입니다 뭔가 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 
관련 문제