posts - 5, comments - 2, trackbacks - 0, articles - 5
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          關于clientWidth取值問題【摘】

          Posted on 2009-11-23 11:03 Just Do It 閱讀(883) 評論(2)  編輯  收藏

          http://hi.baidu.com/bluedream_119/blog/item/dc377d4bef83aff783025c68.html

          關于獲取各種瀏覽器可見窗口大小:
          <script>
          function getInfo()
          {
          var s = "";
          s = " 網頁可見區域寬:" document.body.clientWidth;
          s = " 網頁可見區域高:" document.body.clientHeight;
          s = " 網頁可見區域寬:" document.body.offsetWidth " (包括邊線和滾動條的寬)";
          s = " 網頁可見區域高:" document.body.offsetHeight " (包括邊線的寬)";
          s = " 網頁正文全文寬:" document.body.scrollWidth;
          s = " 網頁正文全文高:" document.body.scrollHeight;
          s = " 網頁被卷去的高(ff):" document.body.scrollTop;
          s = " 網頁被卷去的高(ie):" document.documentElement.scrollTop;
          s = " 網頁被卷去的左:" document.body.scrollLeft;
          s = " 網頁正文部分上:" window.screenTop;
          s = " 網頁正文部分左:" window.screenLeft;
          s = " 屏幕分辨率的高:" window.screen.height;
          s = " 屏幕分辨率的寬:" window.screen.width;
          s = " 屏幕可用工作區高度:" window.screen.availHeight;
          s = " 屏幕可用工作區寬度:" window.screen.availWidth;


          s = " 你的屏幕設置是 " window.screen.colorDepth " 位彩色";
          s = " 你的屏幕設置 " window.screen.deviceXDPI " 像素/英寸";
          //alert (s);
          }
          getInfo();
          </script>
          在我本地測試當中:
          在IE、FireFox、Opera下都可以使用
          document.body.clientWidth
          document.body.clientHeight
          即可獲得,很簡單,很方便。
          而在公司項目當中:
          Opera仍然使用
          document.body.clientWidth
          document.body.clientHeight
          可是IE和FireFox則使用
          document.documentElement.clientWidth
          document.documentElement.clientHeight
          原來是W3C的標準在作怪啊
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          如果在頁面中添加這行標記的話 在IE中:
          document.body.clientWidth ==> BODY對象寬度
          document.body.clientHeight ==> BODY對象高度
          document.documentElement.clientWidth ==> 可見區域寬度
          document.documentElement.clientHeight ==> 可見區域高度
          在FireFox中:
          document.body.clientWidth ==> BODY對象寬度
          document.body.clientHeight ==> BODY對象高度
          document.documentElement.clientWidth ==> 可見區域寬度
          document.documentElement.clientHeight ==> 可見區域高度
          ?
          在Opera中:
          document.body.clientWidth ==> 可見區域寬度
          document.body.clientHeight ==> 可見區域高度
          document.documentElement.clientWidth ==> 頁面對象寬度(即BODY對象寬度加上Margin寬)
          document.documentElement.clientHeight ==> 頁面對象高度(即BODY對象高度加上Margin高)
          而如果沒有定義W3C的標準,則
          IE為:
          document.documentElement.clientWidth ==> 0
          document.documentElement.clientHeight ==> 0
          FireFox為:
          document.documentElement.clientWidth ==> 頁面對象寬度(即BODY對象寬度加上Margin寬)document.documentElement.clientHeight ==> 頁面對象高度(即BODY對象高度加上Margin高)
          Opera為:
          document.documentElement.clientWidth ==> 頁面對象寬度(即BODY對象寬度加上Margin寬)document.documentElement.clientHeight ==> 頁面對象高度(即BODY對象高度加上Margin高)

          評論

          # asdf  回復  更多評論   

          2011-12-29 20:50 by asdfasdf
          askldfjalskdfjlksdfjasldkjfalsdjfalksdjfajsdklfjaklsdjfl;kajsdlkfjlaksdfjl;asdf

          # asdf  回復  更多評論   

          2011-12-29 20:50 by asdfasdf
          asdfasdf

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 桂平市| 新竹县| 陇西县| 将乐县| 康定县| 温州市| 和平县| 翼城县| 六盘水市| 将乐县| 济阳县| 石门县| 和平县| 平原县| 凤凰县| 纳雍县| 临武县| 十堰市| 潜江市| 通许县| 绥化市| 白城市| 濉溪县| 和林格尔县| 铁力市| 托克逊县| 神木县| 远安县| 恭城| 绥芬河市| 灵台县| 邳州市| 常宁市| 塔城市| 舟山市| 扶绥县| 宕昌县| 怀安县| 枞阳县| 凤凰县| 垦利县|