2014-06-20 3 views
0

동적 URL을 기반으로하지만 일부 문제가있는 jQuery 함수를 실행하려고했습니다.자바 스크립트로 현재 동적 URL 가져 오기

내 HTML 파일이 내가 로컬 파일을보고하고있는 URL을

var pathname = window.location.pathname; 
var splitPath = pathname.split("?"); 
var input = splitPath[splitPath.length-1]; 

console.log(pathname); 

을 확인하기 위해 사용하고있는 코드가 myPage.html

라고 말해, 나는 브라우저 /pathname/myPage.html에 넣을 때 내 콘솔 출력 정확히 /pathname/myPage.html. 내가 /pathname/myPage.html?input=yes에 페이지가로드 미세 URL을 변경할 수 있지만, 콘솔은 여전히 ​​한편 /pathname/myPage.html를 기록하는 경우

하지만 지금은 내가 잘못 여기서 뭐하는 거지 input=yes

를보고 싶은데요? 당신은 사용을 시도 할 수

+0

['window.location.search'] (https://developer.mozilla.org/en-US/docs/Web/API/URLUtils.search)를 사용하지 않는 이유는 무엇입니까? –

+0

@DavidThomas 그 이유는 다음과 같습니다. P – Adjit

답변

1

document.location.search?을 다음 모든 것을 반환 window.location.href.

+0

* MDN (출처 : https://developer.mozilla.org/en-US/docs/Web/API/)에 따라 *? URLUtils.search). –

+0

예, '?'를 포함하여 테스트되었습니다. 고마워. – Adjit

1

var pathname = window.location.href; 
console.log(pathname); 
관련 문제