構文 | | document.links[インデクス].href | |
| |
説明
- Areaオブジェクトは,areaタグで表されるイメージ・マップリンクの「0」から始まる配列を作成し,その中に各リンクの情報を格納している。
- 複数のイメージ・マップリンクが存在する場合,インデックスの値がHTMLファイルの記述の上から「0」,「1」。「2」...となっていく。
- 「href」プロパティは,イメージ・マップリンクの情報のうち,リンクのURI全体の値を持つ。
- 読み出し専用。
用例
イメージ・マップ内に設定したリンクのURIの値を取得し書き出す。インデックスの値「0」から,「http://www.nikkeibp.co.jp/」,「http://www.google.co.jp/」,「http://www.google.co.jp/search?hl=ja&q=JavaScript&btnG=Google+検索&lr=」,「JavaScript:Mis()」となる。
<!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>href</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>
*イメージマップリンクのURIの値
<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("URL:",document.links[0].href);
document.write("<br>");
document.write("URL:",document.links[1].href);
document.write("<br>");
document.write("URL:",document.links[2].href);
document.write("<br>");
document.write("URL:",document.links[3].href);
//-->
</script>
</p>
</body></html>
この用例を実行する