linkオブジェクトのhrefプロパティは、リンク先URLを参照します。
<p> <a id="samplelink" href="https://www.htmq.com:8000/js/index.php?q=javascript#link" target="_blank"> サンプルリンク </a> </p> <script> var linkObj = document.getElementById("samplelink"); document.write("<div>hrefは「" + linkObj.href + "」</div>"); document.write("<div>targetは「" + linkObj.target + "」</div>"); document.write("<div>protocolは「" + linkObj.protocol + "」</div>"); document.write("<div>hostnameは「" + linkObj.hostname + "」</div>"); document.write("<div>hostは「" + linkObj.host + "」</div>"); document.write("<div>portは「" + linkObj.port + "」</div>"); document.write("<div>pathnameは「" + linkObj.pathname + "」</div>"); document.write("<div>searchは「" + linkObj.search + "」</div>"); document.write("<div>hashは「" + linkObj.hash + "」</div>"); </script>
“);
document.write(“
“);
document.write(“
“);
document.write(“
“);
document.write(“
“);
document.write(“
“);
document.write(“
“);
document.write(“
“);
document.write(“
“);