Sunday 20 October 2019

javascript - Get the size of the screen, current web page and browser window



How can I get windowWidth, windowHeight, pageWidth, pageHeight, screenWidth, screenHeight, pageX, pageY, screenX, screenY which will work in all major browsers?



screenshot describing which values are wanted


Answer



You can get the size of the window or document with jQuery:




// Size of browser viewport.
$(window).height();
$(window).width();

// Size of HTML document (same as pageHeight/pageWidth in screenshot).
$(document).height();
$(document).width();



For screen size you can use the screen object:



window.screen.height;
window.screen.width;

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...