js的url取值
例如地址: http://www.juuyou.com:8080/test.html?aaa=bbb#dddd
如果要取得域名,一般人应该会去通过indexof(),split(),substring()等方法处理。但有更简单的。
下面说下怎么获取和获取的值为什么:
document.location.protocol — http:
document.location.hostname — www.juuyou.com
document.location.host — www.juuyou.com
document.location.port — :8080
document.location.pathname — /test.html
document.location.hash — #dddd
document.location.search — ?aaa=bbb