maksim09
maksim09

Reputation: 33

Hide URL in browser on Android 2.3 using HTML/javascript

Does somebody know how to hide URL on Android (like full screen) using HTML/javascript?

On iPad (Safari) this is simple and can be done using only a few meta tags.

I have tried something like that:

$(document).ready(function () {
scrollTo(0, 1);
});

But, on Motorola T1, the URL bar is still displayed :(

Upvotes: 0

Views: 2492

Answers (3)

Miklos Krivan
Miklos Krivan

Reputation: 1802

None of any solution above worked for me on Samsung S3 mini phone with Android 4.1.1

But I have followed the mentioned url and there was the absolutely right solution. Thanks for it.

https://gist.github.com/1183357

See Fresheyeball's implementation. That works perfectly in portrait and landscape mode as well.

I just copy here my full example:

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <script type="text/javascript" src="jquery-1.8.3.min.js"></script>
        <script type="text/javascript">
            $(function() {
                hideAddressBar();
            });

            function hideAddressBar() {
                if (navigator.userAgent.match(/Android/i)) {
                    window.scrollTo(0, 0); // reset in case prev not scrolled
                    var nPageH = $(document).height();
                    var nViewH = window.outerHeight;
                    if (nViewH > nPageH) {
                        nViewH = nViewH / window.devicePixelRatio;
                        $('BODY').css('height', nViewH + 'px');
                    }
                    window.scrollTo(0, 1);
                } else {
                    addEventListener("load", function() {
                        setTimeout(hideURLbar, 0);
                        setTimeout(hideURLbar, 500);
                    }, false);
                }
                function hideURLbar() {
                    if (!pageYOffset) {
                        window.scrollTo(0, 1);
                    }
                }
                return this;
            }
        </script>
    </head>
    <body>
        <section>
            <div>
                <h1>First title</h1>
                <p>Just some content</p>
            </div>
        </section>
        <section>
            <div>Any text</div>
        </section>
    </body>
</html>

Of course you need to put the jQuery main js file as well in order this example work properly. You can download from here http://jquery.com/download/

Upvotes: 1

user1091949
user1091949

Reputation: 1933

Try this one. I've used it and it seems to work perfectly on Android. It's from here:
https://gist.github.com/1183357

/*
* Normalized hide address bar for iOS & Android
* (c) Scott Jehl, scottjehl.com
* MIT License
*/
(function( win ){
var doc = win.document;

// If there's a hash, or addEventListener is undefined, stop here
if( !location.hash && win.addEventListener ){

    //scroll to 1
    window.scrollTo( 0, 1 );
    var scrollTop = 1,
        getScrollTop = function(){
            return win.pageYOffset || doc.compatMode === "CSS1Compat" && doc.documentElement.scrollTop || doc.body.scrollTop || 0;
        },

        //reset to 0 on bodyready, if needed
        bodycheck = setInterval(function(){
            if( doc.body ){
                clearInterval( bodycheck );
                scrollTop = getScrollTop();
                win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
            }   
        }, 15 );

    win.addEventListener( "load", function(){
        setTimeout(function(){
            //at load, if user hasn't scrolled more than 20 or so...
            if( getScrollTop() < 20 ){
                //reset to hide addr bar at onload
                win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
            }
        }, 0);
    } );
}
})( this );

Upvotes: 0

dali
dali

Reputation: 164

try this

$(document).ready(function() {

 if (navigator.userAgent.match(/Android/i)) {
 window.scrollTo(0,0); // reset in case prev not scrolled  
 var nPageH = $(document).height();
 var nViewH = window.outerHeight;
 if (nViewH > nPageH) {
   nViewH -= 250;
   $('BODY').css('height',nViewH + 'px');
 }
 window.scrollTo(0,1);
 }
});

it works even if your page is not long enough

Upvotes: 0

Related Questions