简体   繁体   English

检测网站(不是webapp!)是否已添加到主屏幕?

[英]Detecting whether a website (not webapp!) has already been added to home screen?

I've added a JavaScript notification that reminds iOS users to 'Add to home screen' on some of my sites - it's designed so that it only triggers on the User's second visit to the site - but will continue to show after that regardless. 我添加了一个JavaScript通知,提醒iOS用户在我的某些网站上添加“添加到主屏幕” - 它的设计使其仅在用户第二次访问该网站时触发 - 但无论如何都将继续显示。

Is there a way to detect if the user already has this on their homescreen and prevent the notification popping up if they do? 有没有办法检测用户是否已经在他们的主屏幕上有这个并防止通知弹出,如果他们这样做? Also would there be a way that if they close the window, signalling that they don't want to add it, it doesn't come up again? 还有一种方法,如果他们关闭窗口,发出信号,他们不想添加它,它不会再出现?

You can't know whether they've added you but you can know if they are looking at your site via launching it from home screen. 您无法知道他们是否已添加您,但您可以通过从主屏幕启动了解他们是否正在查看您的网站。 To do this, simply check window.navigator.standalone . 要执行此操作,只需检查window.navigator.standalone

Combine that with the best practice of not repeatedly prompting the user (set a cookie once you've prompted them and don't prompt them again until that cookie has expired) and you'll be alright. 将其与不反复提示用户的最佳做法相结合(一旦你提示它就设置一个cookie,并且在cookie过期之前不再提示它)你会没事的。

You can store a value in a cookie and check if they have already visited the site and/or accepted the notification. 您可以将值存储在cookie中,并检查他们是否已访问过该站点和/或接受该通知。 Of course, the values would disappear if they clear their cache. 当然,如果他们清除缓存,这些值就会消失。

You can find more information on cookies with javascript at http://www.w3schools.com/js/js_cookies.asp 您可以在http://www.w3schools.com/js/js_cookies.asp上找到有关javascript cookie的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无论如何,是否可以使用Javascript将添加到主屏幕 - 应用程序图标添加到主屏幕? - Is there anyway to find whether the add to home screen - app icon has been added to home screen using Javascript? 检测文件是否已提供给浏览器?..有点 - Detecting whether or not file has been served to the browser?..kinda PHP检查文件是否已经上传 - PHP to check whether or not a file has been uploaded already iOS:“已添加到主屏幕”网站不会刷新 - iOS: “Added to home screen” website won't refresh 主屏幕持久性上的iPhone WebApp - iPhone WebApp on Home Screen Persistence 你能检查$(this).addClass('selected')是否已经添加到jQuery中 - Can you check if $(this).addClass('selected') has already been added in jquery 如何检测已添加的搜索提供程序? - How to detect search provider which has already been added? 有什么方法可以检测用户是否已将Web应用程序添加到其主屏幕? - Is there any way to detect if a user has added a web app to their home screen? iOS6 - 有没有办法清除缓存的ajax POST请求添加到主屏幕的webapp? - iOS6 - Is there a way to clear cached ajax POST requests for webapp added to home screen? 在反应中检测是否对div的左侧或右侧进行了点击 - Detecting whether a click has been made to the left side or on the right side of div in react
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM