我已经在jQuery中编写了一个脚本,当我的网站作为网络应用加载时,它会为元素添加填充:
<script type='text/javascript'>
jQuery("div").ready(function(){
if (("standalone" in window.navigator) && window.navigator.standalone) {
jQuery(".menu-secondary").css("paddingTop", "20px");
};
});
</script>
我希望将脚本扩展为仅在将网站作为网络应用加载到iPhone或iPod上时才适用。
我试过以下但没有运气:
<script type='text/javascript'>
jQuery("div").ready(function(){
if (("standalone" in window.navigator) && window.navigator.standalone) ||
((navigator.userAgent.match(/iphone|ipod/i))) {
jQuery(".menu-secondary").css("paddingTop", "20px");
};
});
</script>
任何帮助都会非常感激!
答案 0 :(得分:1)
window.navigator.userAgent.match(&#34; iPhone&#34)
这将返回一个应该检查null或length
的数组