[英]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.