アドレス情報を表示する
サンプルソース
<script language="Javascript"> <!-- document.write("protocol = " + window.location.protocol + "<br>"); document.write("host = " + window.location.host + "<br>"); document.write("hostname = " + window.location.hostname + "<br>"); document.write("port = " + window.location.port + "<br>"); document.write("pathname = " + window.location.pathname + "<br>"); document.write("search = " + window.location.search + "<br>"); document.write("hash = " + window.location.hash + "<br>"); --> </script> |
解説
window.location.protocol・・・URL(アドレス)のプロトコル(例:http:)window.location.host・・・URL(アドレス)のホスト名+ポート(例:webroom.hp.infoseek.co.jp:8080)
window.location.hostname・・・URL(アドレス)のホスト名(例:webroom.hp.infoseek.co.jp)
window.location.port・・・URL(アドレス)のポート(例:8080)
window.location.pathname・・・URL(アドレス)のパス(例:/tips/javatips_b5.htm)
window.location.search・・・URL(アドレス)の引数(例:?a=1&b=2)
window.location.hash・・・URL(アドレス)のアンカー名(#以降の文字列)(例:#header)
実行結果
関連する内容