2011-12-19 2 views
1

인 경우 블로거 블로그를 웹 사이트로 변환하려고합니다. 정적 인 홈 페이지를 가지기 위해서 아래의 Javascript 코드를 사용하여 사용자가 홈 페이지에 있는지를 확인합니다. 그러면 게시물 섹션을 숨기고 홈 페이지 "가제트"를 표시합니다. 뭐가 일치해야합니까?url에 범용 변수 plus를 포함한 문이

document.onload = hidepage(); 

function hidepage() { 
if (window.location == "http://website.blogspot.com/" || window.location == "http://website.blogspot.com/?zx=" + ANYTHING) { 
//Checks to see if user is on the home page 
    $(".hentry").hide(); //Hide posts 
    $(".hfeed").hide(); //Hide posts 
} 
else { 
    $("#HTML2").hide(); //hide gadget 
} 

$(".post-title").hide(); //Hide post titles 
} 
+0

그건 질문이 아닙니다. 그래서 당신이 도움을 받고자하는 것이 확실하지 않습니다. – JesseBuesking

답변

1

그냥 if 표현 하반기에 String.indexOf를 사용합니다. 나는 '

if (window.location.href === "http://website.blogspot.com/" || 
    window.location.href.indexOf("/?zx=") > -1) 

참고 :

if (window.location.href === "http://website.blogspot.com/" || 
    window.location.href.indexOf("http://website.blogspot.com/?zx=") > -1) 

또한이 단축 수 : 당신은 내가 당신을 생각하는 무슨 말을하는지 바탕으로

var url = window.location.href; 
if (url === "http://website.blogspot.com/" || url.indexOf("http://website.blogspot.com/?zx=") === 0) { 
    // do stuff 
} 
1

의 경우 조건을 변경하려면 후자가 문자 비교이므로 =====으로 변경했습니다.

+0

왜'> 0'이 아닌'=== 0'입니까? –

+0

오타 였고,'> -1' ... location은'index.h'의 메소드가 없습니다. location.href.indexOf' – isNaN1247

+0

여전히'=== 0'이 아닌가요? 또한,'location' 객체는 문자열이 아니므로'location === '는 항상 false가됩니다. https://developer.mozilla.org/en/DOM/window.location –

관련 문제