IT/Web
Javascript 로 URL 주소 가져오기
SpringUpOhWell!
2016. 4. 21. 21:55
반응형
자바스크립트로 URL 구하기
현재 URL을 http://Godwithus.tistory.com/test/test.php?key=val#getURL 이라고 가정하겠습니다
location.href http://Godwithus.tistory.com/test/test.php?key=val#getURL
location.hostname http://Godwithus.tistory.com
location.pathname /test/test.php
location.protocol http:
location.search ?key=val
location.hash #getURL
location.hash.substr(1) getURL
location.assing("http://www.loads_a_new_document.com"); loads a new document
iframe 에서 부모 URL 구하기
보안 이슈(https://en.wikipedia.org/wiki/Same-origin_policy)로 인하여 부모창의 호스트와 iFrame 의 호스트가 다를 경우 부모창의 URL 에 접근 할 수 없기 때문에 아래와 같은 방법을 사용한다
document.referrer http://Godwithus.tistory.com/test/test.php?key=val
그런데 문제는 부모의 hash 를 구하지 못한다는 것이다
반응형