glenn_r
asked on
javascript how to print out device width
I use the following css3 media query to apply a style when the device width is 768px. I want to write a html page with javascript that prints out the device-width. They i could run this device to find out the device width instead of hunting for it on google. Any ideas what that javascript or jquery would look like. Note jqueyr $(screen).width() is the browser and not the device width.
@media screen and (device-width: 768px) {
html{
background-color: pink;
}
}
@media screen and (device-width: 768px) {
html{
background-color: pink;
}
}
Here you go: http://www.w3schools.com/js/js_window_screen.asp They have example code linked at the bottom of the page that shows all the screen properties on one page.
I'd suggest that you use something like 770px instead of 768px. I had trouble using the exact width and height.
This is from the CSS for one page I've worked on. Screen sizes 480 and lower are in aother section.
/* Tablet Layout: 481px to 768px. Inherits styles from: Mobile Layout. */
@media only screen and (min-width: 481px) {
ASKER
none of those examples get me the device width
i'm not looking for the browser or viewport width
i want to identify the devices width
for example an ipad1 device size is 1024x768
i'm not looking for the browser or viewport width
i want to identify the devices width
for example an ipad1 device size is 1024x768
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
device-width
Here's what i want to do. I want to write javascript to produce the width and device-width values that media queries is using. I have a few devices where I don't know the width and device width and I want to use if for testing.
Media Query Example
@media screen and (max-width: 1024px) {
}
@media (max-device-width: 1024px) {
}
Javascript Example
var width_ = SomeFunctionOrVariableToGe tWidth
var devicewidth_ = SomeFunctionOrVariableToGe tDeviceWid th
Here's what i want to do. I want to write javascript to produce the width and device-width values that media queries is using. I have a few devices where I don't know the width and device width and I want to use if for testing.
Media Query Example
@media screen and (max-width: 1024px) {
}
@media (max-device-width: 1024px) {
}
Javascript Example
var width_ = SomeFunctionOrVariableToGe
var devicewidth_ = SomeFunctionOrVariableToGe