我使用以下脚本添加到我的移动网站的启动屏幕中,一旦将其添加到主屏幕。
<script>
(function(){
var a;
if(navigator.platform === "iPad") {
a = window.orientation!==90||window.orientation === -90 ?
"/assets/img/startup/startup-tablet-landscape.png" :
"/assets/img/startup/startup-tablet-portrait.png";
}
else {
a = window.devicePixelRatio === 2 ?
"/assets/img/startup/startup-retina.png" :
"/assets/img/startup/startup.png";
}
document.write('<link rel="apple-touch-startup-image" href="' + a + '"/>');
})();
</script>
这适用于iPhone而不适用于iPad,我正在新iPad上测试,这有关系吗?我得到的只是一个白色屏幕,然后加载。
答案 0 :(得分:3)
你不需要javascript,你可以使用这个snipplet,它应该自动选择正确的图像:
<!-- For iPhone 4 with high-resolution Retina display: -->
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon-114x114-precomposed.png">
<!-- For first-generation iPad: -->
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="apple-touch-icon-72x72-precomposed.png">
<!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: -->
<link rel="apple-touch-icon-precomposed" href="apple-touch-icon-precomposed.png">
<!-- 320x460 for iPhone 3GS -->
<link rel="apple-touch-startup-image" media="(max-device-width: 480px) and not (-webkit-min-device-pixel-ratio: 2)" href="startup-iphone.png">
<!-- 640x920 for retina display -->
<link rel="apple-touch-startup-image" media="(max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2)" href="startup-iphone4.png">
<!-- iPad Portrait 768x1004 -->
<link rel="apple-touch-startup-image" media="(min-device-width: 768px) and (orientation: portrait)" href="startup-iPad-portrait.png">
<!-- iPad Landscape 1024x748 -->
<link rel="apple-touch-startup-image" media="(min-device-width: 768px) and (orientation: landscape)" href="startup-iPad-landscape.png">