简体   繁体   English

是否可以在Chrome for Android中以编程方式显示网址栏?

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

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). 默认情况下,仅在按下设备的菜单按钮时以及向下滑动页面时才显示(当触摸标记为红色时,请参阅下面的GIF)。 Can the URL bar be shown using JavaScript? 可以使用JavaScript 显示URL栏吗?

GIF显示在Chrome for Android中隐藏/显示网址栏

The solution 解决方案

It is possible only on user input , because of the limitations of the Full Screen API. 由于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. 此功能仅在运行Android 4.4.2的Samsung Galaxy S4上的Chrome 35.0 .1916.141中进行测试。
  • 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. 为避免其他浏览器出错 ,请使用全屏API函数的跨浏览器实现,而不是webkit。
  • This is kind of a hack, so it might become ineffective in future releases of Chrome. 这是一种黑客攻击,因此在将来的Chrome版本中它可能会变得无效
  • Some lag can be seen because of the 600 ms timeout, but the function would be dysfunctional without it. 由于600毫秒的超时,可以看到一些滞后 ,但没有它,功能将失效。
  • 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. 使用window.location更改整个URL会使地址栏重新出现,但是离开/重新加载页面是一种不良副作用。 Changing only window.location.hash or using window.history doesn't help either, even if the URL is modified. 仅更改window.location.hash或使用window.history也无济于事,即使URL已被修改。 None of window.scrollBy , window.scrollTo , window.scrollTop helps. window.scrollBywindow.scrollTowindow.scrollTop帮助。

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. 然后你没有地址栏就全屏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM