Is it possible to programmatically show URL bar in Chrome for Android?

旧街凉风 提交于 2019-11-29 16:00:54

问题


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 only window.location.hash or using window.history doesn't help either, even if the URL is modified. None of window.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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!