3个回答
展开全部
用 JS 获得屏幕分辨率
一.
<script language=javascript>
alert ("分辨率为 " + screen.width + "× " + screen.height );
</script>
二.
自适应判断浏览器和分辨率JS
<SCRIPT LANGUAGE="JavaScript">
<!--
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
var IE1024="";
var IE800="";
var IE1152="";
var IEother="";
ScreenWidth(IE1024,IE800,IE1152,IEother)
}
else{
if (window.navigator.userAgent.indexOf("Firefox")>=1)
{
var Firefox1024="";
var Firefox800="";
var Firefox1152="";
var Firefoxother="";
ScreenWidth(Firefox1024,Firefox800,Firefox1152,Firefoxother)
}
else{
var Other1024="";
var Other800="";
var Other1152="";
var Otherother="";
ScreenWidth(Other1024,Other800,Other1152,Otherother)
}
}
function ScreenWidth(CSS1,CSS2,CSS3,CSS4){
if ((screen.width == 1024) && (screen.height == 768)){
setActiveStyleSheet(CSS1);
}else{
if ((screen.width == 800) && (screen.height == 600)){
setActiveStyleSheet(CSS2);
}else{
if ((screen.width == 1152) && (screen.height == 864)){
setActiveStyleSheet(CSS3);
}else{
setActiveStyleSheet(CSS4);
}}}
}
function setActiveStyleSheet(title){
document.getElementsByTagName("link")[0].href="style/"+title;
}
//-->
</SCRIPT>
一.
<script language=javascript>
alert ("分辨率为 " + screen.width + "× " + screen.height );
</script>
二.
自适应判断浏览器和分辨率JS
<SCRIPT LANGUAGE="JavaScript">
<!--
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
var IE1024="";
var IE800="";
var IE1152="";
var IEother="";
ScreenWidth(IE1024,IE800,IE1152,IEother)
}
else{
if (window.navigator.userAgent.indexOf("Firefox")>=1)
{
var Firefox1024="";
var Firefox800="";
var Firefox1152="";
var Firefoxother="";
ScreenWidth(Firefox1024,Firefox800,Firefox1152,Firefoxother)
}
else{
var Other1024="";
var Other800="";
var Other1152="";
var Otherother="";
ScreenWidth(Other1024,Other800,Other1152,Otherother)
}
}
function ScreenWidth(CSS1,CSS2,CSS3,CSS4){
if ((screen.width == 1024) && (screen.height == 768)){
setActiveStyleSheet(CSS1);
}else{
if ((screen.width == 800) && (screen.height == 600)){
setActiveStyleSheet(CSS2);
}else{
if ((screen.width == 1152) && (screen.height == 864)){
setActiveStyleSheet(CSS3);
}else{
setActiveStyleSheet(CSS4);
}}}
}
function setActiveStyleSheet(title){
document.getElementsByTagName("link")[0].href="style/"+title;
}
//-->
</SCRIPT>
展开全部
//获取屏幕的宽
java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
//获取屏幕的高
java.awt.Toolkit.getDefaultToolkit().getScreenSize().height;
java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
//获取屏幕的高
java.awt.Toolkit.getDefaultToolkit().getScreenSize().height;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用下面的步骤,可以得到屏幕的分辨率:
1、调用Toolkit类的static方法getDefaultToolkit得到一个Toolkit对象:
Toolkit kit = Toolkit.getDefaultToolkit();
2、调用Toolkit对象的getScreenSize方法把屏幕尺寸作为一个Dimension对象返回:
Dimension screensize= kit. getScreenSize();
3、从对象的实例变量width和height中获得屏幕的宽度和高度:
int screenWidth= screensize. width;
int screenHeight= screensize. height;
如下时示例代码:
public class Screen
{
public static void main(String[] args)
{
int screenWidth=((int)java.awt.Toolkit.getDefaultToolkit().getScreenSize().width);
int screenHeight = ((int)java.awt.Toolkit.getDefaultToolkit().getScreenSize().height);
System.out.println(screenWidth+""+screenHeight);
}
}
class ScreenSize
{
private int screenWidth;
private int screenHeight;
public void setScreenWidth(int screenWidth)
{
this.screenWidth=screenWidth;
}
public void setScreenHeight(int screenHeight)
{
this.screenHeight=screenHeight;
}
public int getScreenWidth()
{
setScreenWidth((int)java.awt.Toolkit.getDefaultToolkit().getScreenSize.width);
return screenWidth;
}
public int getScreenHeight()
{
setScreenHeight((int)java.awt.Toolkit.getDefaultToolkit.getScreenSize().height);
return screenHeight;
}
}
1、调用Toolkit类的static方法getDefaultToolkit得到一个Toolkit对象:
Toolkit kit = Toolkit.getDefaultToolkit();
2、调用Toolkit对象的getScreenSize方法把屏幕尺寸作为一个Dimension对象返回:
Dimension screensize= kit. getScreenSize();
3、从对象的实例变量width和height中获得屏幕的宽度和高度:
int screenWidth= screensize. width;
int screenHeight= screensize. height;
如下时示例代码:
public class Screen
{
public static void main(String[] args)
{
int screenWidth=((int)java.awt.Toolkit.getDefaultToolkit().getScreenSize().width);
int screenHeight = ((int)java.awt.Toolkit.getDefaultToolkit().getScreenSize().height);
System.out.println(screenWidth+""+screenHeight);
}
}
class ScreenSize
{
private int screenWidth;
private int screenHeight;
public void setScreenWidth(int screenWidth)
{
this.screenWidth=screenWidth;
}
public void setScreenHeight(int screenHeight)
{
this.screenHeight=screenHeight;
}
public int getScreenWidth()
{
setScreenWidth((int)java.awt.Toolkit.getDefaultToolkit().getScreenSize.width);
return screenWidth;
}
public int getScreenHeight()
{
setScreenHeight((int)java.awt.Toolkit.getDefaultToolkit.getScreenSize().height);
return screenHeight;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询