Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Safari screen.availHeight and statusbar / toolbar / addressbar

I'm trying to get the available screen size in iPhone Safari in order to shrink a container to the height of the screen, minus the statusbar and toolbar.

Since iOS always returns screen dimensions as though the phone is in portrait orientation, I'm using screen.availWidth to work out the height in landscape. The following are the dimensions returned:

screen.width; //320
screen.availWidth; //300

The 20px difference accounts for the top statusbar on the phone but doesn't take into account the button bar (toolbar) at the bottom of the screen.

Is there any property that I can use that would return 268px?

I would just do (screen.availWidth - 32) but there's a chance the user will add the site as a desktop bookmark, in which case this bar won't be present and the 300px value would be correct.

like image 555
howard10 Avatar asked May 09 '12 07:05

howard10


People also ask

Why is address bar on bottom of Safari?

So without any further ado, let's get started. Note: The term Address bar and Tab bar is used interchangeably, and both mean the same in Safari browser on iPhone. However, the bottom tab bar enables the tab switching feature like Safari computer.

How do I get my search bar back on top of Safari?

The easiest method is to move the search bar from within Safari itself. In the address bar at the foot of the screen, tap the AA icon at the left end. If you don't see it, swipe down to scroll up on the open web page and it should appear. From the popup menu, tap Show Top Address Bar.


1 Answers

I don't have the exact answer, but you can determine whether user is in Mobile Safari or in desktop bookmark with navigator.standalone property. With this you could decide whether to substract 32px or not.

Edit: Found the answer. Use <meta name="viewport" content="user-scalable=no, width=device-width, height=device-height" /> and then the correct value can be get from window.innerWidth / window.innerHeight

like image 200
Samuli Hakoniemi Avatar answered Oct 13 '22 20:10

Samuli Hakoniemi