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

后端 未结 2 852
醉梦人生
醉梦人生 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: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.

提交回复
热议问题