JavaScript为提供了许多方法来在Web浏览器地址栏中显示当前URL。您可以使用Window对象的Location对象属性来获取这些详细信息。下面是Location对象的一些属性列表。第一个示例将在Web浏览器中获取当前URL。下面还列出了一些示例可以参考,下面我们来看具体的内容。 
1、href:返回地址栏中显示的整个URL。 var currentURL = window.location.href; 2、host:返回地址栏中URL的主机名和端口。 var currentHost = window.location.host; 3、hostname:只返回地址栏中URL的主机名。 var currentHostname = window.location.hostname; 4、post:仅返回地址栏中URL的端口详细信息。 var currentPort = window.location.port; 5、protocol:返回地址栏中URL的协议。就像URL使用HTTP(不使用SSL)或HTTPS(使用SSL)一样。 var currentProtocol = window.location.protocol; 6、pathname:返回地址栏中URL的路径名(域名后面的值)。 var currentPathname = window.location.pathname; 7、pathname:返回URL的锚点部分,包括hash singh(#)。 var currenthash = window.location.hash; 8、search :返回URL的查询部分,例如以问号(?)开头的部分。 var currentSearchString = window.location.search; 本篇文章到这里就已经全部结束了,更多精彩内容大家可以关注模板之家(www.mb5.com.cn)的其他相关栏目教程!!! 以上就是如何使用JavaScript在Web浏览器中获取当前URL的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章! |