Purl.js可以帮助我们来获取地址栏的一些信息, 可以使用原生js,也可以使用jQuery
| Attributes | Info |
|---|---|
| source | The whole url being parsed |
| protocol | eg. http, https, file, etc |
| host | eg. www.mydomain.com, localhost etc |
| port | eg. 80 |
| relative | The relative path to the file including the querystring (eg. /folder/dir/index.html?item=value) |
| path | The path to the file (eg. /folder/dir/index.html) |
| directory | The directory part of the path (eg. /folder/dir/) |
| file | The basename of the file eg. index.html |
| query | The entire query string if it exists, eg. item=value&item2=value2 |
| fragment or anchor | The entire string after the # symbol |
初始化:
1 | var url; |
运行试试看:
截图如下所示:
