问题
By default, it gets shown only when the device's menu button is pressed and when the page is swiped down (see the GIF below when the touch marker is red). Can the URL bar be shown using JavaScript?
回答1:
The solution
It is possible only on user input, because of the limitations of the Full Screen API. See the demo.
var p;
function showURLBar() {
p = [window.pageXOffset, window.pageYOffset];
document.documentElement.webkitRequestFullscreen();
setTimeout(function () {
document.webkitExitFullscreen();
setTimeout(function () {
scrollTo(p[0], p[1]);
}, 300);
}, 300);
}
Important notes
- This function is tested only in Chrome 35.0.1916.141, on Samsung Galaxy S4, running Android 4.4.2.
- On other devices, it might be necessary to increase the timeouts.
- To avoid errors in other browsers, use a cross-browser implementation of the Full Screen API functions instead of webkit's.
- This is kind of a hack, so it might become ineffective in future releases of Chrome.
- Some lag can be seen because of the 600 ms timeout, but the function would be dysfunctional without it.
- I've checked some other approaches without success. Changing the entire URL using
window.location
makes the address bar reappear, but leaving/reloading the page is an undesirable side effect. Changing onlywindow.location.hash
or usingwindow.history
doesn't help either, even if the URL is modified. None ofwindow.scrollBy
,window.scrollTo
,window.scrollTop
helps.
回答2:
By the use of the word 'device' I'm guessing you mean a mobile device. I fought with this also and just used a shortcut to the page from the desktop of the device. Then you get full screen without the address bar.
来源:https://stackoverflow.com/questions/24480571/is-it-possible-to-programmatically-show-url-bar-in-chrome-for-android