Ker*_*ick 105 javascript iphone bookmarks mobile-safari homescreen
是否可以使用Javascript模拟Mobile Safari书签菜单中的"添加到主屏幕"选项?
window.external.AddFavorite(location.href, document.title);可能与IE类似的东西?
小智 61
在Safari实现Service Worker并遵循Chrome和Firefox设置的方向之前,无法以编程方式将应用程序添加到主屏幕,或者让浏览器提示用户
但是,有一个小型库可以提示用户这样做,甚至指向正确的位置.工作一种享受.
https://github.com/cubiq/add-to-homescreen
Lou*_*arg 50
在MobileSafari中添加任何书签(包括主屏幕上的书签)的唯一方法是使用内置UI,并且Apples无法提供从页面内的脚本执行此操作的任何方式.事实上,我很确定在桌面版Safari上也没有这样做的机制.
小智 8
有一个开源的Javascript库提供相关的东西: mobile-bookmark-bubble
Mobile Bookmark Bubble是一个JavaScript库,可在您的移动Web应用程序底部添加促销泡泡,邀请用户将应用程序添加到其设备的主屏幕.该库使用HTML5本地存储来跟踪是否已经显示促销,以避免不断唠叨用户.
该库的当前实现专门针对Mobile Safari,即iPhone和iPad设备上使用的Web浏览器.
到了 2020 年,这在 Mobile Safari 上仍然是不可能的。
下一个最佳解决方案是显示将页面添加到主屏幕的步骤说明。
// Check if user has seen the message already
const hasSeenInstallPopup = localStorage.getItem("hasSeenInstallPopup");
// Detects if device is on iOS
const isIos = () => {
const userAgent = window.navigator.userAgent.toLowerCase();
return /iphone|ipad|ipod/.test( userAgent );
}
// Detects if device is in standalone mode
const isInStandaloneMode = () => ('standalone' in window.navigator) && (window.navigator.standalone);
// Checks if should display install popup notification:
if (!hasSeenInstallPopup && isIos() && !isInStandaloneMode()) {
showInstallMessage();
localStorage.setItem("hasSeenInstallPopup", true);
}
Run Code Online (Sandbox Code Playgroud)
TLDR:@Craig 在上面有一个更好的答案。
以下是我的原始答案,但我认为它不能充分回答问题。今天我想说你必须尝试一个库来模拟这种效果,因为 WebViews (PWA) 不支持 A2HS。
@Kerrick我想删除我的答案,但不能,因为它已被接受。
旧答案:
是的。大多数现代浏览器都支持渐进式 Web 应用程序的“添加到主屏幕”(或 A2HS)功能。引用Mozilla Web Docs 文章:
添加到主屏幕是现代浏览器中提供的一项功能,允许用户“安装”网络应用程序,即。添加到主屏幕的快捷方式。
另请参阅:caniuse.com 上的 A2HS 浏览器支持
| 归档时间: |
|
| 查看次数: |
163359 次 |
| 最近记录: |