移动终端浏览器默认设置视口的宽度和初始规模。
最近做的一个移动终端的项目,遇到一个默认设置更改的问题。起初非常怀疑是自己的html写的有问题。经过一番页面尺寸的测试之后终于找到问题根源。知道是什么问题就可以找解决的方法了。
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no,height=device-height"/>
<meta name="format-detection" content="telephone=no">
在页面的头部文件中加入了以上设定就ok了。以下是找到的有关于这些设定的解析。记录下来避免忘记。
然而这些设定只在移动终端的浏览器中有效,非移动终端浏览器这些设定是无效的。并且要这些浏览器是基于iPhone而来的。初次涉及移动终端的应用,恼人的事情不只这一件呢,呵呵O(∩_∩)O~
Sets whether a web application runs in full-screen mode.
<meta name="apple-mobile-web-app-capable" content="yes"> |
If content
yes
, the web application runs in full-screen mode; otherwise, it does not. The default behavior is to use Safari to display web content.
You can determine whether a webpage is displayed in full-screen mode using the window.navigator.standalone
Available in iPhone OS 2.1 and later.
Apple extension.
Sets the style of the status bar for a web application.
<meta name="apple-mobile-web-app-status-bar-style" content="black"> |
This meta tag has no effect unless you first specify full-screen mode as described in
If content
default
, the status bar appears normal. If set to black
, the status bar has a black background. If set to black-translucent
, the status bar is black and translucent. If set to default
black
, the web content is displayed below the status bar. If set to black-translucent
, the web content is displayed on the entire screen, partially obscured by the status bar. The default value is default
.
Available in iPhone OS 2.1 and later.
Apple extension.
Enables or disables automatic detection of possible phone numbers in a webpage in Safari on iPhone.
<meta name="format-detection" content="telephone=no"> |
By default, Safari on iPhone detects any string formatted like a phone number and makes it a link that calls the number. Specifying telephone=no
Available in iPhone OS 1.0 and later.
Apple extension.
Changes the logical window size used when displaying a page on iPhone.
<meta name = "viewport" content = "width = 320, |
initial-scale = 2.3, user-scalable = no"> |
Use the viewport meta key to improve the presentation of your web content on iPhone. Typically, you use the viewport meta tag to set the width and initial scale of the viewport.
For example, if your webpage is narrower than 980 pixels, then you should set the width of the viewport to fit your web content. If you are designing an iPhone-specific web application, you should set the width to the width of the device.
“email”
When referring to the dimensions of a device, you should use the constants described in device-width
320
device-height
480
You do not need to set every viewport property. If only a subset of the properties are set, then Safari on iPhone infers the other values. For example, if you set the scale to 1.0
, Safari assumes the width is device-width
device-height
For example, to set the viewport width to the width of the device, add this to your HTML file:
<meta name = "viewport" content = "width = device-width"> |
To set the initial scale to 1.0
, add this to your HTML file:
<meta name = "viewport" content = "initial-scale = 1.0"> |
To set the initial scale and to turn off user scaling, add this to your HTML file:
<meta name = "viewport" content = "initial-scale = 2.3, user-scalable = no"> |
Use the Safari on iPhone console to help debug your webpages as described in
Available in iPhone OS 1.0 and later.
Apple extension.