阻止智能应用横幅在iPad上显示

Prevent Smart app banner from showing on iPad

本文关键字:iPad 显示 智能 应用      更新时间:2023-09-26

我有一个网站,在iOS上使用HTML元标记显示智能应用程序横幅。我希望横幅只出现在iPhone上&iPod。

如何防止它出现在iPad上?

苹果资源:http://developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html

我使用的代码(来自苹果资源):

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

您必须使用Javascript来完成这项工作,因为没有合适的方法可以仅在HTML中进行平台检测。

去掉HTML代码中的元标记,使用下面的代码片段,或者只使用其中的一部分,不管你喜欢什么。如果你想"照原样"使用它,请将它粘贴在身体底部。

(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));