利用iOS中Safari浏览器创建伪Web App
在safari浏览器里有一个“添加到主屏幕”选项,我们可以用来创建伪Web App,下面来了解一下iOS中Safari的私有属性
第一步设置Web App的主屏幕图标:
有两种属性值apple-touch-icon和apple-touch-icon-precomposed,区别就在于是否会应用iOS中自动给图标添加的那层高光。
<link rel="apple-touch-icon-precomposed" sizes="57x57" href="icon-57.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="icon-72.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="icon-114.png">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="icon-144.png">
由于iPhone以及iPad都有两种分辨率的设备存在,图标的尺寸就需要做4个:144×144(iPad Retina)、72×72(iPad)、114×114(iPhone Retina)、57×57(iPhone)。
可以使用sizes尺寸来告诉设备该调用哪个图标。
第二步设置Web App的启动画面
更有趣的是,我们还能设置我们的webApp的桌面图标以及启动画面!
下面分别是iphone、ipod、ipad以及相应retina屏的图标及启动画面设置~需要注意的地方是启动画面的图片大小,在media属性我们可以看到宽高的值,但是这是包括了状态栏的,所以其实图片的真实大小的高度并不是media内的值而是href示例中的大小~
<!-- iPhone -->
<link href="http://taylor.fausak.me/static/images/apple-touch-icon-57x57.png"
sizes="57x57"
rel="apple-touch-icon">
<link href="http://taylor.fausak.me/static/images/apple-touch-startup-image-320x460.png"
media="(device-width: 320px) and (device-height: 480px)
and (-webkit-device-pixel-ratio: 1)"
rel="apple-touch-startup-image">
<!-- iPhone (Retina) -->
<link href="http://taylor.fausak.me/static/images/apple-touch-icon-114x114.png"
sizes="114x114"
rel="apple-touch-icon">
<link href="http://taylor.fausak.me/static/images/apple-touch-startup-image-640x920.png"
media="(device-width: 320px) and (device-height: 480px)
and (-webkit-device-pixel-ratio: 2)"
rel="apple-touch-startup-image">
<!-- iPhone 5 -->
<link href="http://taylor.fausak.me/static/images/apple-touch-startup-image-640x1096.png"
media="(device-width: 320px) and (device-height: 568px)
and (-webkit-device-pixel-ratio: 2)"
rel="apple-touch-startup-image">
<!-- iPad -->
<link href="http://taylor.fausak.me/static/images/apple-touch-icon-72x72.png"
sizes="72x72"
rel="apple-touch-icon">
<link href="http://taylor.fausak.me/static/images/apple-touch-startup-image-768x1004.png"
media="(device-width: 768px) and (device-height: 1024px)
and (orientation: portrait)
and (-webkit-device-pixel-ratio: 1)"
rel="apple-touch-startup-image">
<link href="http://taylor.fausak.me/static/images/apple-touch-startup-image-748x1024.png"
media="(device-width: 768px) and (device-height: 1024px)
and (orientation: landscape)
and (-webkit-device-pixel-ratio: 1)"
rel="apple-touch-startup-image">
<!-- iPad (Retina) -->
<link href="http://taylor.fausak.me/static/images/apple-touch-icon-144x144.png"
sizes="144x144"
rel="apple-touch-icon">
<link href="http://taylor.fausak.me/static/images/apple-touch-startup-image-1536x2008.png"
media="(device-width: 768px) and (device-height: 1024px)
and (orientation: portrait)
and (-webkit-device-pixel-ratio: 2)"
rel="apple-touch-startup-image">
<link href="http://taylor.fausak.me/static/images/apple-touch-startup-image-1496x2048.png"
media="(device-width: 768px) and (device-height: 1024px)
and (orientation: landscape)
and (-webkit-device-pixel-ratio: 2)"
rel="apple-touch-startup-image">
另外iphone5这个特殊尺寸的启动画面的设置会稍有不同,它的宽度必须设置成device-width或者320.并且scale设置成1.0。
<!-- Letterboxed on iPhone 5 -->
<meta name="viewport"
content="width=device-width">
<meta name="viewport"
content="width=320">
<!-- Not letterboxed on iPhone 5 -->
<meta name="viewport"
content="initial-scale=1.0">
<meta name="viewport"
content="width=320.1">
apple-touch-startup-image是用来标示启动画面的,但它不像apple-touch-icon可以指定sizes来告诉设备该使用哪个图片(也有一种说法是在iOS5中已经支持sizes识别了,但没有测试成功),所以只能通过media里的设备分辨率的判断值来识别,而iPhone Retina的分辨率值界于取值之间,所以需要通过webkit的私有属性-webkit-min-device-pixel-ratio:2来鉴别像素密度以进行识别。
启动画面的图片尺寸并非完全等于设备的尺寸,比如iPad2的尺寸是1024×768,但它的启动画面尺寸横向是1024×748,竖向尺寸是768×1004,因为需要减去系统状栏的高度20px,而使用的Retina屏幕的iPhone4以及iPad3则需要减去状态栏的高度40px。
横屏和竖屏:
<link rel="apple-touch-startup-image" media="screen and (orientation: portrait)" href="milanoo_startup.png" /> <!--竖-->
<link rel="apple-touch-startup-image" media="screen and (orientation: landscape)" href="milanoo_startup1.png" /> <!--横-->
iphone:320*460
ipad:
startup_portrait.png 768x1004
startup_landscape.png 748x1024
第三步Web App运行起来要像Native App,那么就要去掉Safari的一些默认控件,比如地址栏、状态栏之类的。
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1.0, maximum-scale=1, user-scalable=no">
apple-mobile-web-app-capable是用来定义应用全屏展示的;在定义了apple-mobile-web-app-capable的前提下,设置状态栏的属性值apple-mobile-web-app-status-bar-style才有效;format-detection的值用于启用或禁用自动检测在网页中可能出现的电话号码;
viewport并非Safari的私有属性,width用于指定宽度,initial-scale指定初始化的缩略比例,minimum-scale指定缩小的比例,而maximum-scale则是放大的比例,当然这些缩放都取决于user-scalable——决定用户是否能缩放页面。
通过主屏幕上点击进入Web APP 形式的网页时候,点击任何一个链接就会跳转到Safari 浏览器并新建一标签页打开所属链接。
问题解决:
<script type="text/javascript">
//iOS Web APP中点击链接跳转到Safari 浏览器新标签页的问题 devework.com
//stanislav.it/how-to-prevent-ios-standalone-mode-web-apps-from-opening-links-in-safari
if(("standalone" in window.navigator) && window.navigator.standalone){
var noddy, remotes = false;
document.addEventListener('click', function(event) {
noddy = event.target;
while(noddy.nodeName !== "A" && noddy.nodeName !== "HTML") {
noddy = noddy.parentNode;
}
if('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes))
{
event.preventDefault();
document.location.href = noddy.href;
}
},false);
}
</script>
相关链接:
https://blog.csdn.net/yz_lby/article/details/17500259
https://blog.csdn.net/boyit0/article/details/52275657
利用iOS中Safari浏览器创建伪Web App的更多相关文章
- iOS中Safari浏览器select下拉列表文字太长被截断的处理方法
网页中的select下拉列表,文字太长的话在iOS的Safari浏览器里会被自动截断,显示成下面这种: 安卓版的浏览器则没有这个问题. 如何让下拉列表中的文字在iOS的Safari浏览器里显示完整呢? ...
- 解决java web中safari浏览器下载后文件中文乱码问题
解决java web中safari浏览器下载后文件中文乱码问题 String fileName = "测试文件.doc"; String userAgent = request.g ...
- iOS中plist的创建,数据写入与读取
iOS中plist的创建,数据写入与读取 Documents:应用将数据存储在Documents中,但基于NSuserDefaults的首选项设置除外Library:基于NSUserDefaults的 ...
- 将iOS中Safari 的默认搜索引擎由google.cn改为google.com的方法
众所周知虽然Google大部分的业务已经迁出中国大陆,访问Google的中国站点只会出现一个投影网站,但是很长一段时间里如果想要访问Google仍然能跳转到google.com.hk这个香港的节点,这 ...
- 蜗牛爱课- iOS中plist的创建,数据写入与读取
iOS中plist的创建,数据写入与读取功能创建一个test.plist文件-(void)triggerStorage{ NSArray *paths=NSSearchPathForDirect ...
- iOS中通过链接地址打开指定APP并传参 by徐文棋
基于项目需要,有时候需要通过一个链接,或者二维码扫描来直接打开我们所开发的客户端. 当然了.客户端也不仅仅是需要被打开,而且还要跳到相应的页面去,因此这里需要传参. 客户端想用链接打开,必须要在inf ...
- 004.Create a web app with ASP.NET Core MVC using Visual Studio on Windows --【在 windows上用VS创建mvc web app】
Create a web app with ASP.NET Core MVC using Visual Studio on Windows 在 windows上用VS创建mvc web app 201 ...
- C#中自己动手创建一个Web Server(非Socket实现)
目录 介绍 Web Server在Web架构系统中的作用 Web Server与Web网站程序的交互 HTTPListener与Socket两种方式的差异 附带Demo源码概述 Demo效果截图 总结 ...
- ios 使用Safari浏览器跳转打开、唤醒app
常常使用Safari浏览器浏览网页点击url会唤醒该站点的手机版app 须要在app的project中设置 1.打开project中的myapp-Info.plist文件 2.打开文件里新增URL T ...
随机推荐
- wamp3.1.0下载地址
WAMP是Windows用来搭建网站或服务器的开源软件,包含Apache + Mysql/MariaDB + Perl/PHP/Python等开发组件,方便快速便捷配置环境,很多朋友说wamp官网下载 ...
- SegmentedControlIOS使用
代码: import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, SegmentedContr ...
- react native获取屏幕的宽度和高度
var Dimensions = require('Dimensions'); var {width,height} = Dimensions.get("window");//第一 ...
- mysql show prifile基本详解
show profile默认情况下,参数处于关闭状态,并保存最近15次的运行结果查看profile是否开启 show variables like '%profi%';开启profile记录功能 se ...
- what's the python之函数及装饰器
what's the 函数? 函数的定义:(return是返回值,可以没有,不过没有的话就返回了None) def wrapper(参数1,参数2,*args,默认参数,**kwargs): '''注 ...
- 自动化工具之二:win32gui
自动化工具win32gui 一.下载安装win32gui 二.Win32gui的使用 1.查找窗体句柄 我们知道的所有空间其实就是窗体,所有的窗口都有一个独立的句柄,要操作任意一个窗体,你都需要找到这 ...
- [django]django配合前端vue前后端联调,django服务端解决跨域(django-cors-headers)
django内部csrf post提交数据解决 https://www.cnblogs.com/iiiiiher/articles/9164940.html 前端写了个页面,里面$.post发现403 ...
- java中Long的比较
Long的比较要用equals而不要用== 当Long为常量且常量值小于一个字节(<=127)时,两个Long指向同一个常量内容: Long userId=127L; Long authorId ...
- Py-numpy的随机函数【转载】
转自:https://blog.csdn.net/u012149181/article/details/78913167 1. numpy.random.rand() numpy.random.ran ...
- 【LeetCode每天一题】3Sum(三数之和)
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find ...