Sam May
Sam May

Reputation: 43

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.

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?

Upvotes: 3

Views: 175

Answers (2)

Robert Levy
Robert Levy

Reputation: 29073

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.

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.

Upvotes: 1

RandomHappenstance
RandomHappenstance

Reputation: 1

You can store a value in a cookie and check if they have already visited the site and/or accepted the notification. 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

Upvotes: 0

Related Questions