Giter Site home page Giter Site logo

philfung / add-to-homescreen Goto Github PK

View Code? Open in Web Editor NEW
98.0 5.0 21.0 4.62 MB

Easily add a website to a user's home screen on IOS/Android/Desktop

License: MIT License

HTML 29.88% JavaScript 1.89% CSS 21.39% TypeScript 46.85%
add-to-homescreen manifest-json mobile-web mobile-web-app mobile-website pwa pwa-apps standalone standalone-app webapp

add-to-homescreen's Introduction

add-to-homescreen 📱 🖥️

Motivation

Add to home screen allows websites and PWA's to work like native apps without registering in the Apple or Google App Stores. Currently, it is very difficult to get users to add web apps to their home screen, limiting the utility of such websites compared to native apps. See related Medium blog post.

This Library

This drop-in JS Library for websites effectively guides a user to add the website to their home screen on IOS, Android and Desktop.
Instructions and UI in this library have been "battle-tested" and has yielded an ~85% home screen install rate on IOS and Android across all ages in past implementations.

Here is a demo (please open on your phone) of library use within a hypothetical app "Aardvark" aardvark-icon

Browser Support

All major browsers on IOS/Android/Desktop are supported. Here are the guides shown for each platform/browser:

IOS - Safari browser

sc-ios-safari

IOS - Chrome browser

sc-ios-chrome

Android - Chrome browser

sc-android-chrome

Desktop - Chrome/Edge browsers

sc-desktop-chromeedge

Desktop - Safari browser

sc-desktop-safari

In-App Mobile Browsers

Users are guided to open the link in the system browser.

Installation

Prerequisite

Make sure your site has the minimum requirements for installing a web app on homescreen for IOS and Android and Desktop.

  1. At https://your-website.com/apple-touch-icon.png, include a square icon of your app that is (1) at least 40 x 40 pixels and (2) specifically named apple-touch-icon.png(example).

  2. At https://your-website.com/manifest.json, include a web manifest file manifest.json (example). Reference the manifest in your index HTML file.

    index.html

    <head>
    ...
    <link rel="manifest" crossorigin="use-credentials" href="manifest.json">
    ..
    </head>

Usage (If you're not making changes to library)

This should be a quick drop-in library into your website.

  1. Include the library JavaScript and CSS files in your header (You can use JSDelivr CDN if you're just using the library directly and not making any changes):

    index.html

    <head>
    ...
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/philfung/[email protected]/dist/add-to-homescreen.min.css">
    <script src="https://cdn.jsdelivr.net/gh/philfung/[email protected]/dist/add-to-homescreen.min.js"></script>
    ...
    </head>
  2. Call the library onload.

    index.html

    <script>
    document.addEventListener('DOMContentLoaded', function () { 
     window.AddToHomeScreenInstance = new window.AddToHomeScreen({
      appName: 'Aardvark',                                   // Name of the app.
                                                             // Required.
      appIconUrl: 'apple-touch-icon.png',                    // App icon link (square, at least 40 x 40 pixels).  
                                                             // Required.
      assetUrl: 'https://cdn.jsdelivr.net/gh/philfung/[email protected]/dist/assets/img/',  // Link to directory of library image assets.
    
      maxModalDisplayCount: -1                               // If set, the modal will only show this many times.
                                                             // Optional. Default: -1 (no limit).  (Debugging: Use this.clearModalDisplayCount() to reset the count)
    });
          
     ret = window.AddToHomeScreenInstance.show('en');        // show "add-to-homescreen" instructions to user, or do nothing if already added to homescreen
                                                             // The only argument is the language to show the messages in (currently only 'de', 'en', 'pt' and 'fr' are available).
    });
    </script>
    </body>

Here's an example implementation.

Special Case: calling the UI later

2-alternate. if you're calling the UI NOT onload, but sometime after (for example, in an onclick() handler for an "Install App" button), then you should still create your the instance onload, but call your UI later on the instance variable with .show()):

index.html

<script>
document.addEventListener('DOMContentLoaded', function () { 

   window.AddToHomeScreenInstance = new window.AddToHomeScreen({...
}));

document.getElementById('my_install_app_button').addEventListener('click', function () {
   window.AddToHomeScreenInstance.show('en');
});
</script>
</body>

This is because some handlers must be created onload.

Usage (If you're making changes to library)

  1. Make changes
  2. Test locally:

Start local server

npm run install
npm run build
npm run start

Load an example page http://127.0.0.1:8081

  1. Build the library into the dist directory
npm run build
  1. Save the dist directory to a CDN of your choice. Follow the steps in the previous section.

Dependencies

No dependencies. This is written in raw ES6 javascript and all css is namespaced to minimize codebase conflict and bloat.

License

License: MIT

add-to-homescreen's People

Contributors

cyberorg avatar jemayn avatar jpjust avatar p4km4n avatar philfung avatar redeye86 avatar rom1ajh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

add-to-homescreen's Issues

Incorrect information displayed for iOS Safari (iPhone 15 Pro)

Hello. I am trying to use this application, but when I test on my phone (iPhone 15 Pro) using the regular Safari browser, it is displaying an incorrect message:

"Tap the button below to open your system browser".

Screen shot:

screenshot

Is there an update needed for newer browsers?

Doesn’t work on iPad, displays “install on mobile device”

If you configure iPad to request mobile site (which is not default), it will display installation instructions but they are incorrect (location of share button is top right, not bottom).

This should work like iPhone regardless of safari configuration.

add-to-homescreen not page specific

Hi,
Works very well as intended
but I have noticed that your add-to-homescreen seems to be domain specific and not page specific
I set it to run only 2 times when user land on the page.
However, Once it has ran twice, your add-to-homescreen does not run again on another page i also need it to run on.
I want add-to-homescreen to be able to run two time on all pages I select it to run it on
Is there a way to achieve this.
Thanks

Idea: Read name / icon from manifest.json

Wouldn't it make sense to read the name and icon of the app from the manifest.json? It is json anyway and linked in the of the page.
I am using the script in a multi-site installation and it is invoked from inside a javascript file that is not site specific. So I don't have the information about the name in the first place. At first I thought about reading the application name and icon path from some data-attribute (in body or html tag). But the manifest has to be linked anyway for this to work and the name and icon could be used as the default.

Button is not translated

The file ios-add-to-home-screen-button.svg is a graphic that contains both the icon and the text "Add to homescreen". Therefore the text is not part of the localization. I think the the text should be removed from the svg and the icon should be used alone with a localized text.

I have three problems

Hi,

I think it's great what you do to notify with a PWA app message, thank you very much.

I have three problems:

  1. On Windows 11 PC I cannot close the installation message in any browser, I can close the message in Chrome and Samsung browser on Android. (allowUserToCloseModal: true,)

On the other hand, the message on PC about widows 11 chrome shows that it cannot be installed, when it can be installed PWA

  1. If I install the PWA application, the installation message still appears. Can you stop reporting the PWA installation message?

  2. On Android when browsing, Edge shows the installation message with the up arrow, but the correct thing is that it will show the down arrow, in the direction of the edge setting button.

Best regards,

Eugenio

Adding 'ru' locale

Hey and thank you for you for the product! Would you be open to merge a pull request with 'ru' locale?

CSS Conflicts

I'm using bootstrap as my CSS framework. That framework defines a css class called .modal. That causes the add-to-homescreen modal to be stretched out since it also uses the .modal classname. You probably want to have webpack (or something else) add a namespace/prefix to all of the classnames used, or have your css rules only apply within the top level div made by the library.
Screenshot 2023-09-14 at 10 39 12 AM

In Chrome Browser instead of the text maybe show the user the steps to install PWA in Chrome ?

In Chrome Browser instead of the text :
Please open this website on a mobile device.
Installing to your home screen is currently only supported on IOS and Android.

maybe show the user the steps to install PWA in Chrome ?
screenshot_2024_02_20_at_07_49_42
The webpage in chrome browsers offer to the users the option to install app in windows,
maybe place a modal with the steps to install the PWA in chrome browsers ?
screenshot_2024_02_20_at_08_01_42

Issue with using button to launch AddToHomeScreenInstance

I used your code sample to try to use a BUTTON tag to launch the AddToHomeScreenInstance, but no matter what I try, when I click on the button, the function launches the modal creates the the DIV ("adhs-container"), but then immediately closes/removes the DIV.

<script> document.getElementById('addToHomeScreen').addEventListener('click', function () { window.AddToHomeScreenInstance = new window.AddToHomeScreen({ appName: 'App Name', appIconUrl: '/mobile/iOS.png', assetUrl: '/_scripts/add-to-homescreen-1.9/assets/img/', allowUserToCloseModal: true, maxModalDisplayCount: -1 }); ret = window.AddToHomeScreenInstance.show('en'); }); </script>

If you'd like I could provide an example video or URL.

Do you happen to have a working sample?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.