覚えておくと便利そうなのでメモ。 現在のページのホスト名(ドメイン)を取得する 「location.hostname」で取得可能。 テストソース <script type="text/javascript"> <!-- document.write(location.hostname); // --> </script> URLからホスト名(ドメイン)を取得する(抜き出す) 「.split('/')[2]」でホスト名を分割可能。 テストソース <script type="text/javascript"> <!-- document.write(location.href.split('/')[2] + '<br />'); document.write('http://www.yahoo.co.jp/'.split('/')[2]); // --> </script>
