Answer the question
In order to leave comments, you need to log in
How to hide the address bar in the browser on android?
I'm making a mini toy on js for a tablet. I want the size of the visible part to occupy the entire space, including the address bar, but so that there is no scrolling. In other words - I want to hide the address bar when loading and when the screen is rotated.
I do it like this:
//load вызывается при <body onload="load()">
function load() {
hideAddressBar();
// 1
//window.addEventListener("orientationchange", function () {
// hideAddressBar();
//});
}
function hideAddressBar() {
if (navigator.userAgent.match(/Android/i) != null) {
//window.orientation 0 - 180 - landscape; 90 and -90 portrait
document.documentElement.style.height = window.outerHeight + 'px';
setTimeout(window.scrollTo(0, 1), 0);
}
}
addressBarHeight = window.outerHeight - window.innerHeight;
@media screen and (orientation: portrait) {
html, body {
height: 100%;
/*!important;*/
}
}
@media screen and (orientation: landscape) {
html, body {
height: 100%;
/*!important;*/
}
}
Answer the question
In order to leave comments, you need to log in
This crutch works for me ;-)
window.onload = function () {
hideAddressBar();
window.addEventListener("orientationchange", function () {
hideAddressBar();
}, false);
}
function hideAddressBar() {
setTimeout(function () {
document.body.style.height = window.outerHeight + 'px';
setTimeout(function () {
window.scrollTo(0, 1);
}, 1100);
}, 1000);
return false;
}
www.html5rocks.com/en/mobile/fullscreen
https://github.com/sindresorhus/screenfull.js
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question