我正在使用这个库"智能应用程序横幅":"^2.0.0"来显示智能应用程序横幅,它工作正常,但我遇到的问题是这个。
我已经创建了一个带有指向我的网站的网络视图的 android 应用程序,问题是智能应用程序横幅仍然显示在网络视图中,让用户下载应用程序没有任何意义,因为他已经在使用该应用程序。
如何从 webview 中隐藏它,并且仅在他们从移动设备访问该网站时才显示在我的网站上。
目前我使用这种代码的和平:
<script src="assets/js/smart-app-banner.js"></script>
<script type="text/javascript">
new SmartBanner({
daysHidden: 15, // days to hide banner after close button is clicked (defaults to 15)
daysReminder: 90, // days to hide banner after "VIEW" button is clicked (defaults to 90)
appStoreLanguage: 'us', // language code for the App Store (defaults to user's browser language)
title: 'Winnova',
author: 'Starcut LLC',
button: 'VIEW',
store: {
ios: 'On the App Store',
android: 'In Google Play',
windows: 'In Windows store'
},
price: {
ios: 'FREE',
android: 'FREE',
windows: 'FREE'
}
// , theme: '' // put platform type ('ios', 'android', etc.) here to force single theme on all device
// , icon: '' // full path to icon image if not using website icon image
// , force: 'ios' // Uncomment for platform emulation
});
</script>
您可以在 WebView 设置中设置自定义用户代理,并在 Web 应用程序中使用它。
webview.getSettings().setUserAgentString("my-android-app");
然后在您的 Web 应用程序中,您可以执行以下操作:
<script>
if (navigator.userAgent !== 'my-android-app') {
new SmartBanner({
...
})
}
</script>
但请注意,如果您使用网络分析,我不会更改用户代理。