js擷取螢幕的寬度高度以及window.open的用法

來源:互聯網
上載者:User

轉自:http://hi.baidu.com/zhuifengh2o/item/4cba119a95b69837336eebe0

 

123 <script>         alert(screen.width + "*" + screen.height)        </script>

輸出當前螢幕的寬度和高度;

12345678910111213 <SCRIPT  LANGUAGE="JavaScript">         var s = "網頁可見地區寬:" + document.body.clientWidth;         s += "\r\n網頁可見地區高:" + document.body.clientHeight;         s += "\r\n網頁本文全文寬:" + document.body.scrollWidth;         s += "\r\n網頁本文全文高:" + document.body.scrollHeight;         s += "\r\n網頁本文部分上:" + window.screenTop;         s += "\r\n網頁本文部分左:" + window.screenLeft;         s += "\r\n螢幕解析度的高:" + window.screen.height;         s += "\r\n螢幕解析度的寬:" + window.screen.width;         s += "\r\n螢幕可用工作區高度:" + window.screen.availHeight;         s += "\r\n螢幕可用工作區寬度:" + window.screen.availWidth;         alert(s);        </SCRIPT>

document.body.clientWidth ==> BODY對象寬度
 document.body.clientHeight ==> BODY對象高度

 document.documentElement.clientWidth ==> 可見地區寬度
 document.documentElement.clientHeight ==> 可見地區高度

輸出網頁的各部分寬高值;

123 <script>             window.open('Default.aspx''newwindow''height=500, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')     </script>

window.open的用法:

default.aspx:要開啟的頁面
newwindow:視窗名稱,也可以為_self,_blank等參數
height:視窗高度
width:視窗寬度
toolbar:是否顯示工具列(yes,no)
menubar:是否顯示功能表列(yes,no)
scrollbars:是否出現捲軸(yes,no)
resizable:是否可以改變視窗大小(yes,no)
location:是否顯示地址欄(yes,no)
status:是否顯示狀態列(yes,no)
top,left:視窗開啟時的座標;

12345678 <script>            function centerWindow(url, w, h) {                l = (screen.width - w) / 2                t = (screen.height - h) / 2                window.open(url, ''"height=" + w + ",width=" + h + ",top=" + t + ",left=" + l + "");            }       </script>       <input  type="button"  onclick="centerWindow('http://www.youth21.i.sohu.com','400','400')"/>

開啟一個新的頁面置中顯示;開啟空白頁centerwindow(’about:blank’,800,500)

1234567891011121314 <SCRIPT  LANGUAGE="JavaScript">         redirectPage();         function redirectPage() {             /*var  url640x480  =  "http://www.baidu.com";**記得改相應的頁面*/        var url800x600 = "http://www.baidu.com";             var url1024x768 = "http://youth21.i.sohu.com";             /*if  ((screen.width  ==  640)  &&  (screen.height  ==  480))                window.location.href=  url640x480;*/        if (screen.width <= 800)                 window.location.href = url800x600;             else if ((screen.width >= 1024))                 window.location.href = url1024x768;         }      </script>

根據解析度大小或螢幕寬度開啟不同的頁面;

 

1234567891011121314151617 空間首頁 http://hi.baidu.com/zhuifengh2o      風雲人物 http://hi.baidu.com/zhuifengh2o/archive/tag/hourman      電腦檔 http://hi.baidu.com/zhuifengh2o/archive/tag/pc      文章 http://hi.baidu.com/zhuifengh2o/archive/tag/article      美圖 http://hi.baidu.com/zhuifengh2o/archive/tag/image      視頻 http://hi.baidu.com/zhuifengh2o/archive/tag/movie      遊戲 http://hi.baidu.com/zhuifengh2o/archive/tag/game      網站知識 http://hi.baidu.com/zhuifengh2o/archive/tag/web      網路工程 http://hi.baidu.com/zhuifengh2o/archive/tag/network%20engineer

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.