js物件導向學習筆記之九(BOM 與 DOM 中常用屬性分析),bomdom

來源:互聯網
上載者:User

js物件導向學習筆記之九(BOM 與 DOM 中常用屬性分析),bomdom
一  BOM對象 window 的 相關屬性1. 使用者配置機器設定物件 navigator

 navigator.userAgent //該屬性可以查看使用者機器瀏覽器的配置   "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4"

2. 使用者uri訪問地址 location

   主    機:host: "www.baidu.com"                           
   主機名稱:hostname: "www.baidu.com"
   完整uri :href: "http://www.baidu.com/s?wd=%E5%A6%82%E4%B"
   域    名:origin: "http://www.baidu.com"
   路    徑:pathname: "/s"
   端 口 號:port: ""
   協議類型:protocol: "http:"
   重新載入:reload: function  無參數 直接調用
   重新載入:replace: function 有參數 調用後 不會在history中產生
   GET 參數:search: "?wd=aaa&lang=zh_cn&name=lizsi"

//擷取使用者url 上的參數   //直接使用 getParam('name')   function getParam(param){      var getarr = (window.location.search.substring(1)).split('&');   var getparam = {};   for(var j in getarr){   var temp = getarr[j].split('=');   temp[0] = temp[0].replace(' ','');//去掉變數名中的空格   getparam[temp[0]] = temp[1];   }   return getparam[param];   }   //對於pathinfo模式的擷取 直接使用getpathinfo(1); 從1開始   function getpathinfo(index){   var getarr = (window.location.pathname.substring(1)).split('/');   return getarr[parseInt(index)-1];   }

3. 曆史訪問記錄 history

   只允許訪問本網域名稱下的記錄
   後退 一 頁:back: function 無參數 直接調用
   前進 一 頁:forward: function 無參數 直接調用
   返回指定頁:go: function -1 後退一頁 0 重新整理當前頁 1 前進一頁 2 前進倆頁
   pushState: function () 參數
   replaceState: function () 參數

 //詳情查看 http://www.zhangxinxu.com/study/201306/ajax-page-html5-history-api.html?area=pudong//點擊過的 加入記錄var query = this.href.split("?")[1];history.pushState({ title: title }, title, location.href.split("?")[0] + "?" + query);var title = $(this).text().replace(/\d+$/, "");document.title = title;    //監聽 相關事件window.addEventListener("popstate", function() {        history.replaceState(null, document.title, location.href.split("?")[0]);    });

4. 螢幕對象 screen

   螢幕可見高度: availHeight: 667
   螢幕可見寬度: availWidth: 375
   螢幕解析度:   colorDepth: 24
   螢幕高度:     height: 667
   螢幕寬度:     width: 375
   availLeft: 0
   availTop: 0

二  DOM 對象 document1. 緩衝 cookie

 //直接使用 cookieParam('name')   function cookieParam(param){      var getarr = document.cookie.split(';');   var getparam = {};   for(var j in getarr){   var temp = getarr[j].split('=');   temp[0] = temp[0].replace(' ','');//去掉變數名中的空格   getparam[temp[0]] = temp[1];   }   return getparam[param];   }









聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.