window.location / window.navigator.userAgent ——獲取瀏覽器地址 / 信息(BOM)

1、window.location——獲取瀏覽器地址瀏覽器

描述:返回結果的數據格式是個對象,還有不少子方法url

經常使用方法:spa

(1)window.location.href ——瀏覽器地址code

  描述:獲取到的和window.location內容同樣對象

(2)window.location.search ——獲取url?後面的內容blog

(3)window.location.hash —— url#後面的內容字符串

 

2、window.navigator.userAgent —— 獲取瀏覽器信息hash

描述:瀏覽器不一樣結果不一樣。包括瀏覽器內核,當前版本等io

方法:class

(1)判斷瀏覽器是不是IE

if ( window.navigator.userAgent.indexOf('MSIE') != -1 ) {  //查找字符串MSIE,若是MSIE存在,就是IE
    alert('我是ie');
} else {
    alert('我不是ie');
}
相關文章
相關標籤/搜索