防止在iPad上显示智能应用横幅 [英] Prevent Smart app banner from showing on iPad

查看:170
本文介绍了防止在iPad上显示智能应用横幅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,该网站使用HTML meta标签在iOS上显示智能应用横幅.我只希望横幅广告显示在iPhone& iPod.

I have a website that shows a smart app banner on iOS using an HTML meta tag. I want the banner only to show up on iPhones & iPods.

如何防止它出现在iPad上?

How can I prevent it from showing up on iPads?

Apple资源: http://developer.apple.com/库/ios/#documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html

Apple resource: http://developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html

我正在使用的代码(来自Apple资源):

The code I'm using (from the Apple resource):

<meta name="apple-itunes-app" content="app-id=myAppStoreID">

推荐答案

您必须使用Javascript来完成此操作,因为没有适当的方法来仅使用HTML进行平台检测.

You'll have to do this using Javascript, since there is no proper way to do platform detection solely in HTML.

在您的HTML代码中删除meta标记,并使用以下代码段,也可以仅使用其中的一部分,但是您愿意.如果您想按原样使用它,请将其粘贴在主体底部.

Get rid of the meta tag in your HTML code and use the following snippet, or just use parts of it, however you like. If you want to use it 'as-is', paste it at the bottom of the body.

(function($){
  var is_iPad = navigator.userAgent.match(/iPad/i) != null;

  // Fill in your Apple-App stuff here
  var app_id = "<YOUR_APPLE_APP_ID>",
      affiliate_data = null,
      app_argument = null;

  // exclude iPad
  if(!is_iPad) {
    var meta = $("<meta>"), content = 'app-id=' + app_id;
    meta.attr('name', 'apple-itunes-app');

    // Optional stuff (only when filled in)
    if(affiliate_data) content += ', affiliate-data=' + affiliate_data;
    if(app_argument) content += ', app-argument=' + app_argument;

    // Apply
    meta.attr('content', content);
    $('head').append(meta);
  }
}(jQuery));

这篇关于防止在iPad上显示智能应用横幅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆