移动端WebApp隐藏地址栏的方法
作者:junjie 时间:2022-09-26 20:26:29
1、很多资料说,添加以下代码,可以隐藏地址栏,但我试了很多次,貌似不成功啊。
<meta name="apple-mobile-web-app-capable" content="yes" />
2、我们可以通过另一种方法来隐藏地址栏。在页面加载完成之后滚动窗口,这个确实有效,唯一要注意的是页面高度必须够高,核心代码如下:
<script type="text/javascript">
addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false);
function hideURLbar(){
window.scrollTo(0,1);
}
</script>
3、但是当页面高度自适应窗口(height:100%),以上方法就不适用了,我们需要采用特殊方法:
$('div').css("height",window.innerHeight+100); //强制让内容超过
window.scrollTo(0, 1);
$("div").css("height",window.innerHeight); //重置成新高度
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false); //如果不想让页面滑动,可以加上这段代码
4、分享一下开源项目
移动前端界面进去的时候,我们会看到地址工具条,这看起来不怎么像一个APP,那么怎么隐藏掉这个地址条,下面提供了一个比较合适的代码,支持ios和Android.
/*! Normalized address bar hiding for iOS & Android (c) @scottjehl MIT License */
(function( win ){
var doc = win.document;
// If there's a hash, or addEventListener is undefined, stop here
if(!win.navigator.standalone && !location.hash && win.addEventListener ){
//scroll to 1
win.scrollTo( 0, 1 );
var scrollTop = 1,
getScrollTop = function(){
return win.pageYOffset || doc.compatMode === "CSS1Compat" && doc.documentElement.scrollTop || doc.body.scrollTop || 0;
},
//reset to 0 on bodyready, if needed
bodycheck = setInterval(function(){
if( doc.body ){
clearInterval( bodycheck );
scrollTop = getScrollTop();
win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
}
}, 15 );
win.addEventListener( "load", function(){
setTimeout(function(){
//at load, if user hasn't scrolled more than 20 or so...
if( getScrollTop() < 20 ){
//reset to hide addr bar at onload
win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
}
}, 0);
}, false );
}
})( this );
详细请访问:https://github.com/scottjehl/Hide-Address-Bar
如果你的浏览器支持标签隐藏的话:
<meta name="apple-mobile-web-app-capable" content="yes" />
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Maven本地jar引用的实现方法
完美解决idea没有tomcat server选项的问题
![](https://img.aspxhome.com/file/2023/3/113213_0s.jpg)
SpringMVC RESTFul实战案例访问首页
![](https://img.aspxhome.com/file/2023/8/80918_0s.png)
SpringBoot使用validation-api实现参数校验的示例
![](https://img.aspxhome.com/file/2023/4/124714_0s.jpg)
Mybatis Plugin拦截器开发过程详解
javaweb上传下载实例完整版解析(上)
![](https://img.aspxhome.com/file/2023/4/63114_0s.jpg)
Java实战之实现用户登录
![](https://img.aspxhome.com/file/2023/0/69110_0s.png)
浅析Java中JSONObject和JSONArray使用
java poi sax方式处理大数据量excel文件
Java ThreadPoolExecutor的参数深入理解
SpringBoot上传文件到本服务器 目录与jar包同级问题
![](https://img.aspxhome.com/file/2023/9/84199_0s.jpg)
SpringAOP 如何通过JoinPoint获取参数名和值
![](https://img.aspxhome.com/file/2023/1/69351_0s.png)
SpringBoot集成Elasticsearch过程实例
![](https://img.aspxhome.com/file/2023/6/70486_0s.png)
java8中的默认垃圾回收器(GC)
![](https://img.aspxhome.com/file/2023/2/86842_0s.png)
java实现单人版五子棋游戏
![](https://img.aspxhome.com/file/2023/0/63060_0s.png)
C# 大小写转换(金额)实例代码
Android使用CardView作为RecyclerView的Item并实现拖拽和左滑删除
![](https://img.aspxhome.com/file/2023/0/138690_0s.png)
C# ArrayList、HashSet、HashTable、List、Dictionary的区别详解
Java中Validated、Valid 、Validator区别详解
Android 实现滑动的六种方式
![](https://img.aspxhome.com/file/2023/2/138452_0s.gif)