Reputation: 65
I am able to get Add to home screen popup on my website example.com but when I open my website with www.example.com, I again get the popup and on clicking on add, it adds the wpa again in the home screen.
How can I prevent this from happening as its useless to have two wpa icons of the same website?
Upvotes: 0
Views: 1281
Reputation: 99
You could add some JavaScript code to remove the following tag whenever the user visits the www
site.
<link rel="manifest" href="/manifest.json">
Example:
if (window.location.host.startsWith('www.') {
const manifestLink = document.querySelector("link[rel='manifest']")
manifestLink.parentNode.removeChild(manifestLink)
}
Upvotes: -1
Reputation: 2612
Easiest option is to simply redirect www calls to non-www calls. So the users never actually stay in that different subdomain.
If for some reason you can't do that, on install of the PWA you could save a cross subdomain cookie just to have a "flag" set that the user installed the PWA. Then, in your code you listen to beforeinstallprompt
event, and do not prompt the install if the cookie exists.
Upvotes: 3