Web Developer's Room
HOME > JavaScript サンプル集 > ブラウザ     

ブラウザ

アドレス情報を表示する

<html>
<body>

<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>

</body>
</html>

【解説】
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)
 サンプル


関連リンク
  • ブラウザの情報を表示する
  • ブラウザの状態を表示する
  • 「前へ戻る」「次へ進む」の操作をする
  • 指定したページ分移動する



  • スポンサードリンク


    (C) Web Developer's Room All rights reserved.