1 如何检测浏览器的类型?
var ua = navigator.userAgent;
var isChrome = ua.indexOf('Chrome');
console.log('is Chrome?', isChrome > 0, navigator.userAgent);
console.log('电脑屏幕大小:', screen.width, screen.height)
2 如何拆解URL的各个部分?
// location
console.log(location.href); // 完整的url地址,http://localhost:8080/JS-Professional/begin/02-%E5%9F%BA%E7%A1%80%E8%BF%9B%E9%98%B6/01-%E4%BB%8E%E5%9F%BA%E7%A1%80%E5%88%B0%E8%BF%9B%E9%98%B6.html?_ijt=i8ctmkc87dvh03tdaf51rn5v1i
console.log(location.protocol) // http/https
console.log(location.host, location.hostname) // www.52tech.tech
console.log(location.pathname); // host之后的全部内容,JS-Professional/begin/02-%E5%9F%BA%E7%A1%80%E8%BF%9B%E9%98%B6/01-%E4%BB%8E%E5%9F%BA%E7%A1%80%E5%88%B0%E8%BF%9B%E9%98%B6.html
console.log(location.search); // search就是?之后的全部内容,?_ijt=i8ctmkc87dvh03tdaf51rn5v1i(包括?)
console.log(location.hash); // #后面的内容(包括#)