jquery、ドメイン、URLの取得 質問する

jquery、ドメイン、URLの取得 質問する

jQuery でドメイン名を取得するにはどうすればいいですか?

ベストアンサー1

これには jQuery は必要ありません。シンプルな JavaScript で十分です。

alert(document.domain);

実際に動作を見てみましょう:

console.log("Output;");  
console.log(location.hostname);
console.log(document.domain);
alert(window.location.hostname)

console.log("document.URL : "+document.URL);
console.log("document.location.href : "+document.location.href);
console.log("document.location.origin : "+document.location.origin);
console.log("document.location.hostname : "+document.location.hostname);
console.log("document.location.host : "+document.location.host);
console.log("document.location.pathname : "+document.location.pathname);

ドメイン関連のその他の値については、次のプロパティを確認してください。window.locationlocation.hostオンラインで。のコンテンツは と異なる可能性があるため、 の方が良いオプションであることがわかるかもしれませんdocument.domain。たとえば、 の URLhttp://192.168.1.80:8080には の IP アドレスのみが含まれますdocument.domainが、 の IP アドレスとポート番号の両方が含まれますlocation.host

おすすめ記事