構文
 
  document.links[インデクス].hostname
インデクス
添番
総合 インデックス
プロパティ
FirefoxIE

説明

  • Areaオブジェクトは,areaタグで表されるイメージ・マップリンクの「0」から始まる配列を作成し,その中に各リンクの情報を格納している。
  • 複数のイメージ・マップリンクが存在する場合,インデックスの値がHTMLファイルの記述の上から「0」,「1」,「2」...となっていく。
  • 「hostname」プロパティは,イメージ・マップリンクのURI情報のうち,ホスト名部分の値を持つ。
  • 読み出し専用。

用例

イメージマップ内に設定したリンクのURIの値のうち,ホスト名部分の値を取得し書き出す。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>hostname</title>
<script type="text/javascript">
<!--
function Mis() { alert("イメージマップのエリア外です!!") }
function MessCr() { document.Fmess.fmess.value = "" }

</script>
<style type="text/css">
<!--
body { background-color: #ffffff; }
-->
</style>
</head>
<body>
*イメージマップリンクのホストネームの値
<p>
<map name="ARIA_1">
    <area shape=rect coords=13,9,73,69 href="http://www.nikkeibp.
co.jp/" target="_Open" onMouseOver="document.Fmess.fmess.value = '日経BP'" onMouseOut="MessCr()"> <area shape=circle coords=119,38,29 href="http://www.google.
co.jp/" target="_Open" onMouseOver="document.Fmess.fmess.value = 'Googl'" onMouseOut="MessCr()"> <area shape=poly coords=160,69,188,7,222,69 href= "http://www.google.co.jp/search?hl=ja&q=JavaScript&btnG=Google+
検索&lr=" target="_Open" onMouseOver="document.Fmess.fmess.value = 'Googl検索結果'" onMouseOut="MessCr()"> <area shape=rect coords=0,0,234,81 href="JavaScript:Mis()" onMouseOver="MessCr()"> </map> <img src="MAP.jpg" usemap="#ARIA_1" border=0 width="234" height= "81" alt="ARIATEST"> </p> <p> <form name="Fmess"> <input type="text" name="fmess" size=20> </form> </p> <p> <script type="text/javascript"> <!-- document.write("リンク数:",document.links.length); document.write("<br>"); document.write("ホストネーム:",document.links[0].hostname); document.write("<br>"); document.write("ホストネーム:",document.links[1].hostname); document.write("<br>"); document.write("ホストネーム:",document.links[2].hostname); //--> </script> </p> </body></html>

この用例を実行する