iphone development blog

Wednesday, January 16, 2008 @ 11:28 AM

Hiding the Address Bar: Take 2

We've been receiving some feedback that the following code (responsible for hiding Safari's address bar) does not work on iPod Touch:

function hideAddressBar() { window.scrollTo(0, 1); }

No one on this end has an iPod Touch, so we can't test to see if that's true or not, but I've had my own problems with this code in the past, so here are some additional things to try and keep in mind.

Try using the following code instead. It doesn't require you to add onload="hideAddressBar()" to your body tag and has proved more reliable in the past.

addEventListener('load', function() { setTimeout(hideAddressBar, 0); }, false);
function hideAddressBar() { window.scrollTo(0, 1); }

Additionally, window.scrollTo(0, 1) does NOT seem to work if you include external CSS files using the following method:

<link rel="stylesheet" type="text/css" href="_assets/css/styles.css" />

Instead, do this:

<style type="text/css">
@import "_assets/css/styles.css";
</style>

Hope this helps!

//Ryan Jennings

Labels: , ,


MindComet at 11:28 AM - View Post