Web Viewport Size
if you ever had to deal with the full size of an HTML document, I know that feeling bro!
The Most Difficult Thing To Get Right Ever!
I mean, even google maps had some problem with that, preferring a user agent sniffing like technique rather than finding the real size of the window. This image is directly from latest Maximiliano Firtman post, a post you should read regardless this single topic!The Useless window.screen
The object you might decide to check for is completely pointless for this purpose ... and the reason is simple: screen does not give any meaningful number to the Web field. The size of the screen in pixel means nothing when the viewport meta tag is set to scale 1, as example. The size means nothing in any case since it's about the full size of the screen and not the current DOM, viewport, window, size. TheavailWidth/Height
property isn't that trustable neither, URL bar on the top or on the bottom, or both, could be in place ... how you gonna deal with that ... Not only screen Problems
The webOS browser is a freaking cool one and still more recent than many other Webkit stock browsers stuck in some android 2.3.something ... so why would you drop webOS support now? Most likely, is gonna be just another slice of compatible devices you gonna have in your portfolio. Well, webOS, and I am talking about Palm Pre 1 and 2, has an horrible bug: you change orientation, things start zooming in and out out of control ... WHY??? Gosh it tok a while to understand how to fix it ... still no idea "why" thought!Full Screen and iOS 6 safari Mobile
Problems ain't solved with latest Apple Operating System, actually ... problems are more than expected. The new 'full screen" feature provided by iOS6 does not obviously fire the"orientationchange"
event, it fires "resize"
one once in full screen and does not fire a thing once it goes back ... here again google maps trusting user agent sniffing like based approach: How lovely is that massive, wasted, white rectangle at the bottom ? What basically every single Web app is doing wrong right now, is to increase the full screen size by those (in)famous 60 pixels so that after they can call window.scroll(0, 0);
... well, all these software must be updated in order to understand that full screen, does not mean navigator.standalone
neither means that the height of the document should be increased by 60 ... got it? IE 6, 7, 8, and 9 Mobile WTFucks!!!
Best part is about these browsers ... specially the mobile one, at least in my Samsung WP7 Omnia Phone, I had to decrease the height by 75 pixels when in portrait, and 5 pixels while in landscape ... and that was completely random but ... you know, it worked :D For all other Desktop IE < 9 versions well ... many fixes and shit about scroll bars but hey ... I don't care, I think I have solved almost everything!The Test Case
Well it's kinda simple, you check this page, and you see a 1 red pixel as full screen border no matter what Mobile or Desktop browser you are using ... it should just work and please let me know if it does not, thanks!The Module
It's part of a repository I am keeping updated with completely random, but tested, stuff ... here it is, a 1.57KB (843 bytes gzipped) piece of code that could make your full screen life much easier, isn't it?How Does It Work
Well, theindex.html
source code should give you some hint but here the basic: Above example will make your canvas full screen no matter which device is running it .. aint that cool!
window.addEventListener("viewportsize", function (e) {
// here you change what you want
// the 'e' object will have a 'result' property
// containing width and height, e.g.
myCanvas.width = e.result.width;
myCanvas.height = e.result.height;
}, false);
Comments
Post a Comment