1. JS+PHP 獲取屏幕解析度然後保存到變數里。
<?php
function getScreen(){
if(!$_GET["screenX"]){
echo '<script>location=location.href+"?screenX="+screen.width+"&screenY="+screen.height;</script>';
exit;
}
$screenX=$_GET["screenX"];
Return $screenX;
}
echo getScreen();
?>
2. 怎麼用js獲取手機屏幕的解析度
function a(){
"屏幕寬高為:"+screen.width+"*"+screen.height;
}
其它:
網頁可見區域寬:document.body.clientWidth
網頁可見區域高:document.body.clientHeight
網頁可見區域寬:document.body.offsetWidth (包括邊線的寬)
網頁可見區域高:document.body.offsetHeight (包括邊線的寬)
網頁正文全文寬:document.body.scrollWidth
網頁正文全文高:document.body.scrollHeight
網頁被捲去的高:document.body.scrollTop
網頁被捲去的左:document.body.scrollLeft
網頁正文部分上:window.screenTop
網頁正文部分左:window.screenLeft
屏幕解析度的高:window.screen.height
屏幕解析度的寬:window.screen.width
屏幕可用工作區高度:window.screen.availHeight
屏幕可用工作區寬度:window.screen.availWidth
HTML精確定位:scrollLeft,scrollWidth,clientWidth,offsetWidth
scrollHeight: 獲取對象的滾動高度。
scrollLeft:設置或獲取位於對象左邊界和窗口中目前可見內容的最左端之間的距離
scrollTop:設置或獲取位於對象最頂端和窗口中可見內容的最頂端之間的距離
scrollWidth:獲取對象的滾動寬度
offsetHeight:獲取對象相對於版面或由父坐標 offsetParent 屬性指定的父坐標的高度
offsetLeft:獲取對象相對於版面或由 offsetParent 屬性指定的父坐標的計算左側位置
offsetTop:獲取對象相對於版面或由 offsetTop 屬性指定的父坐標的計算頂端位置
event.clientX 相對文檔的水平座標
event.clientY 相對文檔的垂直座標
event.offsetX 相對容器的水平坐標
event.offsetY 相對容器的垂直坐標
document.documentElement.scrollTop 垂直方向滾動的值
event.clientX+document.documentElement.scrollTop 相對文檔的水平座標+垂直方向滾動的量
3. 怎樣用js判斷手機屏幕的解析度,根據不同的解析度給定不一樣的事件.急求!!!
用screen.width可以判斷屏幕解析度的寬度,用screen.height可以判斷屏幕解析度的高度!
if (screen.width >= 1440){
//這里執行事件1
}else if (screen.width >= 1366){
//這里執行事件2
}else if (screen.width >= 800){
//這里執行事件3
}else {
//這里執行事件4
}
4. js如何獲取屏幕英寸(注意不是獲取解析度像素值啊)
你用捲尺量顯示屏的有效發光顯示面的對角線尺寸,記下有多少寸,然後用這個尺寸換算成英寸就可以了!
5. 求問Javascript如何獲取屏幕的解析度(PPI/DPI)
獲取PPI:
function js_getDPI() {
var arrDPI = new Array;
if (window.screen.deviceXDPI) {
arrDPI[0] = window.screen.deviceXDPI;
arrDPI[1] = window.screen.deviceYDPI;
}
else {
var tmpNode = document.createElement("DIV");
tmpNode.style.cssText = "width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden";
document.body.appendChild(tmpNode);
arrDPI[0] = parseInt(tmpNode.offsetWidth);
arrDPI[1] = parseInt(tmpNode.offsetHeight);
tmpNode.parentNode.removeChild(tmpNode);
}
return arrDPI;
}
window.onload=function(){
alert("當前屏幕PPI "+js_getDPI());
}
6. html如何通過JS獲得顯示器解析度,然後再跳轉到不同的頁面
一般是根據不同解析度來調用輸出不同的css 來達到自適應。除非您的頁面復雜得無法通過css 重寫來達到,只有靠新頁面來實現就用跳轉。但是現在的網站都是通過輸出css來做的了 像京東 tmall都是。新跳轉不科學 體驗不好
我是這樣寫的:
var qwid=screen.width;
if(qwid<=1210){
document.write('<link href="w9.css" rel="stylesheet" type="text/css" />');
}
7. 用javascript 獲取屏幕解析度 來決定網頁中元素位置的問題
沒那麼麻煩,css就可以解決的。
比如你想居中的圖片為<img src="pic.gif">,你把它放在這個<div align="center" style="margin-left:auto;margin-right:auto;width:400px"><img src="pic.gif"></div>裡面,這樣就居中了,因為div的左右外邊距都是auto,也就是自動的,也就是讓左右外邊距大小一致,所以左右自適應,div就會居中,這個辦法是經常用到的,就是把div這個塊級元素給居中,希望能幫到您,要是有問題請追問,我幫你解答,呵呵..
下面給你個完整的例子:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>div居中</title>
</head>
<body>
<div style="margin-left:auto;margin-right:auto;width:500px;height:200px;text-align:center;border:1px solid red;">這里可以放一張圖片</div>
</body>
</html>
8. js可以獲取手機解析度大小么
當然可以
<script language="JavaScript">
document.write("當前瀏覽器解析度大小為:"+screen.width+"x"+screen.height)
</script>
9. js如何算出瀏覽器的像素是多少像素每英寸
網頁可見區域寬:document.body.clientwidth
網頁可見區域高:document.body.clientheight
網頁可見區域寬:document.body.offsetwidth (包括邊線和滾動條的寬)
網頁可見區域高:document.body.offsetheight(包括邊線的寬)
網頁正文全文寬:document.body.scrollwidth
網頁正文全文高:document.body.scrollheight
網頁被捲去的高:document.body.scrolltop
網頁被捲去的左:document.body.scrollleft
網頁正文部分上:window.screentop
網頁正文部分左:window.screenleft
屏幕解析度的高:window.screen.height
屏幕解析度的寬:window.screen.width
屏幕可用工作區高度:window.screen.availheight
屏幕可用工作區寬度:window.screen.availwidth
屏幕設置 window.screen.colordepth 位彩色
屏幕設置 window.screen.devicexdpi 像素/英寸
分享一些js判斷屏幕解析度的代碼。
一般可以通過下面的代碼判斷解析度
復制代碼代碼示例:
<script language="javascript">
<!-- begin
function redirectpage() {
var wjb51=screen.width;
var hjb51=screen.height;
alert("經系統檢測,你的屏幕解析度為 " + wjb51+"*"+ hjb51 + "by 腳本之家jb51.net");
}
// end -->
</script>
js判斷瀏覽器解析度
復制代碼代碼示例:
<script>
function screenwidth(){
if (screen.width == 1440){
alert("1440*900");
}else if (screen.width == 800){
alert("800*600");
}else if (screen.width == 1152){
alert("1152*864");
}else {
alert("do not know!");
}
}
</script>
<input type="button" name="" value="fenbianli " onclick=" screenwidth()"/>
說明:這段js代碼可改造一下,改為screen.width>=1024 screen.width=800兩種情況
所以,選擇使用下面的代碼:
復制代碼代碼示例:
if(screen.width>=1440){
alert('寬屏幕可以載入廣告了');
//一些廣告代碼
}
用js判斷不同解析度調用不同的css樣式文件
根據顯示器不同的解析度,樣式文件調用的也不一樣。
復制代碼代碼示例:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>js判斷不同解析度調用不同的css樣式_www.jbxue.com</title>
<link rel="stylesheet" id="sc" type="text/css" href="css/c1.css"/>
<script type="text/javascript">
window.onload=function(){
var sc=document.getelementbyid("sc");
var d=document.getelementbyid("d");
if(screen.width>1024) //獲取屏幕的的寬度
{
sc.setattribute("href","css/c2.css"); //設置css引入樣式表的路徑
d.innerhtml = "你的電腦屏幕寬度大於1024,我的寬度是 1200px, 背景色現在是紅色。";
}
else{
sc.setattribute("href","css/c1.css");
d.innerhtml = "你的電腦屏幕寬度小於或是等於1024,我的寬度是 960px, 背景色現在是藍色。";
}
}
</script>
</head>
<body>
<div id="d"></div>
</body>
</html>
c1.css中內容
復制代碼代碼示例:
*{ margin:0; padding:0;}
div{ width:960px; height:400px; margin:0 auto; background:blue; color:#ffffff;}
c2.css中內容
復制代碼代碼示例:
*{ margin:0; padding:0;}
div{ width:1200px; height:400px; margin:0 auto; background:red; color:#fff;}
10. jquery怎麼獲取瀏覽器屏幕解析度
<script type="text/javascript">
$(document).ready(function()
{
alert($(window).height()); //瀏覽器當前窗口可視區域高度
alert($(document).height()); //瀏覽器當前窗口文檔的高度
alert($(document.body).height());//瀏覽器當前窗口文檔body的高度
alert($(document.body).outerHeight(true));//瀏覽器當前窗口文檔body的總高度 包括
border padding margin
alert($(window).width()); //瀏覽器當前窗口可視區域寬度
alert($(document).width());//瀏覽器當前窗口文檔對象寬度
alert($(document.body).width());//瀏覽器當前窗口文檔body的高度
alert($(document.body).outerWidth(true));//瀏覽器當前窗口文檔body的總寬度 包括
border padding margin
alert(screen.height);//顯示器解析度,只能用JavaScript代碼獲取
alert(screen.width);
})
</script>
網頁可見區域寬: document.body.clientWidth
網頁可見區域高: document.body.clientHeight
網頁可見區域寬: document.body.offsetWidth (包括邊線的寬)
網頁可見區域高: document.body.offsetHeight (包括邊線的高)
網頁正文全文寬: document.body.scrollWidth
網頁正文全文高: document.body.scrollHeight
網頁被捲去的高: document.body.scrollTop
網頁被捲去的左: document.body.scrollLeft
網頁正文部分上: window.screenTop
網頁正文部分左: window.screenLeft
屏幕解析度的高: window.screen.height
屏幕解析度的寬: window.screen.width
屏幕可用工作區高度: window.screen.availHeight