js獲取電腦分辨率的思路及操作
更新時(shí)間:2013年11月22日 17:09:07 作者:
用戶要求不同的分辨率,彈出窗口的位置不同,下面是本文的一些想法,并附有示例,喜歡的朋友可以收藏下
在做頁面時(shí),用戶要求,不同的分辨率,彈出窗口的位置不同,我想是不是先獲得屏幕寬度,然后付值給變量,再在onclick中設(shè)置參數(shù)
<script>
alert(screen.width+"*"+screen.height)
</script>
<script>
function centerWindow(url,w,h){
l=(screen.width-w)/2
t=(screen.height-h)/2
window.open(url,'','left='+l+',top='+t+',width='+w+',height='+h)
}
</script>
<input type=button onclick="centerWindow('about:blank',200,200)">
---------------------------------------------------------------
<body>
<SCRIPT LANGUAGE="JavaScript">
var s ="網(wǎng)頁可見區(qū)域?qū)挘?+ document.body.clientWidth;
s+="\r\n網(wǎng)頁可見區(qū)域高:"+ document.body.clientHeight;
s += "\r\n網(wǎng)頁正文全文寬:"+ document.body.scrollWidth;
s += "\r\n網(wǎng)頁正文全文高:"+ document.body.scrollHeight;
s += "\r\n網(wǎng)頁正文部分上:"+ window.screenTop;
s += "\r\n網(wǎng)頁正文部分左:"+ window.screenLeft;
s += "\r\n屏幕分辨率的高:"+ window.screen.height;
s += "\r\n屏幕分辨率的寬:"+ window.screen.width;
s +="\r\n屏幕可用工作區(qū)高度:"+ window.screen.availHeight;
s +="\r\n屏幕可用工作區(qū)寬度:"+ window.screen.availWidth;
alert(s);
</SCRIPT>
---------------------------------------------------------------
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function redirectPage() {
/*var url640x480 = "http://www.yourweb.com/640x480.html";**記得改相應(yīng)的頁面*/
var url800x600 = "index1.asp";
var url1024x768 = "index2.asp";
/*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;
}
// End -->
</script>
這段代碼是根據(jù)不同的屏幕顯示不同的頁面
下面是傳遞這個(gè)參數(shù)的
<script language=JavaScript>
document.write("<a href='WebStat/index.asp'>");
document.write("<img src='WebStat/count.asp?Referer=<%=refer%>
&Width="+escape(screen.width)+"&Height="+escape(screen.height)+
"' border=0 width=1 height=1>");
document.write("</a>");
</script>
復(fù)制代碼 代碼如下:
<script>
alert(screen.width+"*"+screen.height)
</script>
復(fù)制代碼 代碼如下:
<script>
function centerWindow(url,w,h){
l=(screen.width-w)/2
t=(screen.height-h)/2
window.open(url,'','left='+l+',top='+t+',width='+w+',height='+h)
}
</script>
<input type=button onclick="centerWindow('about:blank',200,200)">
---------------------------------------------------------------
<body>
<SCRIPT LANGUAGE="JavaScript">
var s ="網(wǎng)頁可見區(qū)域?qū)挘?+ document.body.clientWidth;
s+="\r\n網(wǎng)頁可見區(qū)域高:"+ document.body.clientHeight;
s += "\r\n網(wǎng)頁正文全文寬:"+ document.body.scrollWidth;
s += "\r\n網(wǎng)頁正文全文高:"+ document.body.scrollHeight;
s += "\r\n網(wǎng)頁正文部分上:"+ window.screenTop;
s += "\r\n網(wǎng)頁正文部分左:"+ window.screenLeft;
s += "\r\n屏幕分辨率的高:"+ window.screen.height;
s += "\r\n屏幕分辨率的寬:"+ window.screen.width;
s +="\r\n屏幕可用工作區(qū)高度:"+ window.screen.availHeight;
s +="\r\n屏幕可用工作區(qū)寬度:"+ window.screen.availWidth;
alert(s);
</SCRIPT>
---------------------------------------------------------------
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function redirectPage() {
/*var url640x480 = "http://www.yourweb.com/640x480.html";**記得改相應(yīng)的頁面*/
var url800x600 = "index1.asp";
var url1024x768 = "index2.asp";
/*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;
}
// End -->
</script>
這段代碼是根據(jù)不同的屏幕顯示不同的頁面
下面是傳遞這個(gè)參數(shù)的
復(fù)制代碼 代碼如下:
<script language=JavaScript>
document.write("<a href='WebStat/index.asp'>");
document.write("<img src='WebStat/count.asp?Referer=<%=refer%>
&Width="+escape(screen.width)+"&Height="+escape(screen.height)+
"' border=0 width=1 height=1>");
document.write("</a>");
</script>
您可能感興趣的文章:
- android計(jì)算pad或手機(jī)的分辨率/像素/密度/屏幕尺寸/DPI值的方法
- 通過js判斷訪客顯示器屏幕分辨率并給出提示
- Android的單位以及屏幕分辨率詳解
- Android基礎(chǔ)之使用Fragment適應(yīng)不同屏幕和分辨率(分享)
- Js控制彈窗實(shí)現(xiàn)在任意分辨率下居中顯示
- Android加載大分辨率圖片到手機(jī)內(nèi)存中的實(shí)例方法
- JS測試顯示屏分辨率以及屏幕尺寸的方法
- android實(shí)用工具類分享(獲取內(nèi)存/檢查網(wǎng)絡(luò)/屏幕高度/手機(jī)分辨率)
- JS獲取當(dāng)前網(wǎng)頁大小以及屏幕分辨率等
- C#如何動(dòng)態(tài)設(shè)置屏幕分辨率
相關(guān)文章
JavaScript或jQuery 獲取option value值方法解析
這篇文章主要介紹了JavaScript或jQuery 獲取option value值方法解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05基于JavaScript實(shí)現(xiàn)百葉窗動(dòng)畫效果不只單純flas可以實(shí)現(xiàn)
看到這種百葉窗效果的動(dòng)畫,以為是用flash做的,下面通過本文給大家介紹基于JavaScript實(shí)現(xiàn)百葉窗動(dòng)畫效果,需要的朋友參考下吧2016-02-02IE的事件傳遞-event.cancelBubble示例介紹
關(guān)于event.cancelBubble,Bubble就是一個(gè)事件可以從子節(jié)點(diǎn)向父節(jié)點(diǎn)傳遞,下面有個(gè)不錯(cuò)的示例,大家可以感受下2014-01-01js trim函數(shù) 去空格函數(shù)與正則集錦
在javascript中處理文本框輸入值的時(shí)候,經(jīng)常要用到"去掉前后空白"的功能。用過jQuery的朋友都知道,jQuery提供了一個(gè)trim()這樣的功能函數(shù),可以很輕松幫我們實(shí)現(xiàn)這樣的效果。2009-11-11基于JavaScript實(shí)現(xiàn)單選框下拉菜單添加文件效果
這篇文章主要介紹了基于JavaScript實(shí)現(xiàn)單選框下拉菜單添加文件效果的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06