HTMLAnchorElement.hrefã¨Element.getAttribute("href")ã®éã
JavaScriptãªããã§URIã®ç¤ºããªã½ã¼ã¹ãã©ãããããã¨ãã«ãã©ããã¦ã絶対URIã欲ãããã¨ããããã ãã©ãé å¼µã£ã¦èªåã§çµã¿ç«ã¦ãªãã¦ããç¸æãAè¦ç´ ãªãæå¤ã¨ç°¡åã«åããã¿ããã
<a id="bar" href="../foo/bar.html">bar</a>
ãããªæãã®Aè¦ç´ ããã£ãã¨ãã¦ãæ®éã«HTMLAnchorElementãªãã¸ã§ã¯ãã®hrefããããã£ãåç
§ããã¨è§£æ±ºæ¸ã¿ã®çµ¶å¯¾URIãå
¥ã£ã¦ãããããã
ããã§Element.getAttribute()ã使ãã¨ç¾å¨è¨å®ããã¦ããå¤ãã®ãã®ãåãã¦ãã¾ãã
var link = document.getElementById('bar'); console.log(link.href); // => http://example.com/path/to/foo/bar.html console.log(link.getAttribute('href')); // => ../foo/bar.html
ä»æ§ããã¾ãã¡ããããªã
ããã£ã¦ã¿ãã¨ããã¨å¸¸èããããã ãã©ãã©ãã¾ã§ä¿¡é ¼ãã¦ããã®ãããã©ã¦ã¶äºææ§ã¨ãã©ããªã®ãããã¾ãã¡ããããªãã£ãã
DOM Level 2ã§è¦å®ããã¦ããã¨ããè¨è¿°ããã£ãã®ã§DOM Level 2 HTMLのHTMLAnchorElementã®ã¨ãããè¦ã¦ã¿ãã¨ã
- href of type DOMString
- The absolute URI [IETF RFC 2396] of the linked resource. See the href attribute definition in HTML 4.01.
ã¨æ¸ããã¦ããã®ã§ããã®å±æ§ã絶対URIãæ±ãã®ã¯ç¢ºããªããã ã
ãã ããã¾ãã«ããã£ããªãæ¸ãã¦ããã®ã§ãç¸å¯¾URIãå
¥ããå ´åã¯ã©ããªãã®ããèªåçã«çµ¶å¯¾URIã«å¤æãã¦ãããã®ããããã¨ãè¨å®ããå´ã絶対URIãè¨å®ããªããã°ãããªãã®ããã¨ããã¾ãã¡ããããããªãã
ã¡ãã£ã¨è©¦ããæãã ã¨ç¸å¯¾URIãçªã£è¾¼ãã§ãèªã¿ã ãã¨ãã«ã¯çµ¶å¯¾URIã¨ãã¦èªã¿åºãã模æ§ã
ãç¸å¯¾URIã絶対URIã«å¤æãããã¯ããã¯ãã®ã²ã¨ã¤ã¨ãã¦ãHTMLAnchorElementãçæãã¦hrefããããã£ããåãåºãã¨ããã®ãæã è¦ãããã®ã§ããã£ã¨å¤§æ¦ã®ç°å¢ã§åããã ãããããããã£ã¨ããã