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

后端 未结 2 850
醉梦人生
醉梦人生 2021-01-01 06:53

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 U

相关标签:
2条回答
  • 2021-01-01 07:23

    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.

    0 讨论(0)
  • 2021-01-01 07:26

    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.
    0 讨论(0)
提交回复
热议问题