Solved

Trying to find a cross broswer solution to find either the screen resolution or browser resolution.

Posted on 2011-03-15
2
228 Views
Last Modified: 2012-05-11
$(window).width();   // returns width of browser viewport
$(document).width(); // returns width of HTML documentI have a php site that needs to know the screen resolution OR the browser resolution to correctly place an absolute position <div></div>

The OS's are OSX 10.6, WinXp Pro, Win 7 Pro
Browsers are IE6,IE7,IE8,IE9,Safari>5,misc firefox ..

I can get document.width/document.height to work in safari.
I can't get it to work in IE

I can get mild success with the jquery library in IE, but not safari
(http://api.jquery.com/width/ :::
$(window).width();   // returns width of browser viewport
$(document).width(); // returns width of HTML document
)

What works all over the place ??
0
Comment
Question by:Imaginx
2 Comments
 
LVL 20

Expert Comment

by:Mark Brady
ID: 35142019
I don't think there is a cross browser solution sorry. At least I have never seen one. That's why you should use a conditional query to see which browser is being used, then set the right code depending on what browser they have.

<!--[if IE 6]>
// put IE6 code in here
<![endif]-->
and so on for all the other browsers.
0
 
LVL 9

Accepted Solution

by:
EZFrag earned 500 total points
ID: 35144947
Hi there,

You could try the snippet below. It might just work....

Hope it helps ^_^
var width,height;
if (self.innerHeight) // all except Explorer
{
	width = self.innerWidth;
	height = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
{
	width = document.documentElement.clientWidth;
	height = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
	width = document.body.clientWidth;
	height = document.body.clientHeight;
}

Open in new window

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now