document.location的属性

示例html完整路径为:

http://10.10.3.117:8500/html/ypt/index.html

alert("document.location.href:"+document.location.href);

描述:设置或返回主机名和当前URL 的端口号

结果:http://10.10.3.117:8500/html/ypt/index.html

alert("document.location.hash:"+document.location.hash);

描述:设置或返回从井号(#) 开始的URL(锚)

结果:


alert("document.location.host:"+document.location.host);

描述:设置或返回主机名和当前URL的端口号

结果:10.10.3.117:8500


alert("document.location.hostname:"+document.location.hostname);

描述:设置或返回当前URL的主机名

结果:10.10.3.117


alert("document.location.pathname:"+document.location.pathname);

描述:设置或返回当前URL的路径部分

结果:/html/ypt/index.html


alert("document.location.port:"+document.location.port);

描述:设置或返回当前URL的端口号

结果:8500

原文地址:https://www.cnblogs.com/cczhoufeng/p/3824786.html