Sunday, April 17, 2011

How to hide the url address bar on a web page on Blackberry

Here's how to minimize the url address bar in a web page on a blackberry (blackberry 6 anyways).

Put this script at the bottom of the page, or call it ondocumentready:

if(navigator.userAgent.toLowerCase().indexOf('blackberry')>0)window.scrollTo(0,40);

It causes the browser to scroll down 40 pixels, which essentially makes the browser bar hide itself.

3 comments:

  1. Note that if you still have content loading (for example, a good sized image) when the above javascript code runs, the browser may not scroll to the full extent of your request. To solve this problem, implement the above on a delayed basis, e.g.,
    if(navigator.userAgent.toLowerCase().indexOf('blackberry')>0)var t=setTimeout("window.scrollTo(0,59)",2000);.
    In this example, the scroll will not occur for 2 seconds (2000 milliseconds), hopefully allowing the content to finish loading (if not, increase the time). I have found that for the browser included with OS 6.0, you need to scroll by 59 pixels in order to remove the bar AND avoid the arrow at the top that indicates content has scrolled off screen.

    ReplyDelete
  2. @anonymous, good point. the best time to do it would be ondocumentready

    ReplyDelete
  3. Hi I'm still new to BB webworks development.
    I would like to know why url bar don't completely hide on the BB bold 9900 since I'm testing my web app on this device even if you increase the pixels, but works on other devices such as the Torch

    Thanks in advanced

    ReplyDelete