JavaScript入門講座

Home > areaオブジェクト > hrefプロパティ

hrefプロパティ

areaオブジェクトのhrefプロパティはイメージマップ・リンクのURLを返します。ページのリンク情報は配列で格納されているのでIndex番号を指定してプロパティの値を取得します。

書式document.links[index番号].href
対応Internet ExplorerFireFoxChromeSafariOpera
イメージマップ・リンクのURL
使用例イメージマップ・リンクのURLを表示する。

<html>
<head>
<title>JavaScript area href</title>
<script type="text/javascript">
function dispHref(){
    for(var i=0 ; i < document.links.length ; i++){
        alert('URL:' + document.links[i].href);
    }	
}
</script>
</head>
<body>
<map name="area_test">
<area shape="rect" coords="16,17,96,93"
 href="http://www.google.co.jp/" alt="Googleへ">
<area shape="circle" coords="147,55,40"
 href="http://www.yahoo.co.jp/" alt="Yahooへ">
<area shape="poly" coords="53,111,16,182,96,182"
 href="http://jp.msn.com/" alt="MSNへ">
<area shape="poly" coords="147,104,106,150,147,190,192,150"
 href="http://www.excite.co.jp/" alt="Exciteへ">
</map>
<img src="imgarea.jpg" usemap="#area_test"
 border=0 width="200px" height="200px">
<form name="fm">
イメージマップ・リンクのURLを表示する
<input type="button" value="確認" onclick="dispHref()">
</form>
</body>
</html>
						
関連メンバ
hostイメージマップ・リンクのホスト名とポート番号
hostnameイメージマップ・リンクのホストコンピュータ名
lengthイメージマップ・リンク数
pathnameイメージマップ・リンクのパス名
portイメージマップ・リンクのポート番号
protocolイメージマップ・リンクのプロトコル
targetイメージマップ・リンクのターゲット属性
searchイメージマップ・リンクの問合せ部分