2012-05-17 4 views
2

나는 다양한하는 HREF 몇 가지 링크를 가지고 같은,이 값에 대한 최종 URL을 얻으려면 : BTW 내가 클릭 처리를위한 코드를 원하지 않는href 값에서 최종적인 URL을 얻는 방법은 무엇입니까?

http://localhost/ -> http://localhost/ 
localhost   -> http://mysite.example/localhost 
firstpage   -> http://mysite.example/firstpage 
/anotherpage  -> http://mysite.example/anotherpage 
#anchor1   -> http://mysite.example/currentpage#anchor1 
/#anchor2   -> http://mysite.example/#anchor2 

. 나는 그걸 할 수있어.

답변

5

$("a:first").prop("href")은 href 속성에 텍스트를 제공하는 $("a:first").attr("href")이 아니라 첫 번째 앵커 태그의 전체 URL을 제공합니다.

+0

순수 js로 풀 수 있습니까? – kbec

+1

확실히 :'element.href'는 전체 URL을 반환하고'element.getAttribute ("href")'는 정의 된대로 속성 값을 반환합니다. – wrock

관련 문제