> Add to home screen
I found that many iPhone and iPad users don’t know that they can add their favorite web sites to the Home Screen and interact with them like standard native applications. This script helps them to discover this great feature and suggests the steps needed to add your web app to the dashboard.

Project info
Name: Add to Home screen
Last code update: 2012.01.26 – v2.0
Device compatibility: iPhone/Ipod touch >=3.1.1, iPad >=3.2.
QR Code opens demo page.
Support development
If this script saved your day and you wish to support future developments you may consider sending some funds via PayPal or Flattr.
Overview
The script places a floating balloon inviting the user to add your application to the home screen. Version 2 of the script takes advantage of iOS5 native fixed elements positioning and gracefully degrades to a javascript only version on iOS4.
The default message looks like this:

The code is compatible with iPhone/iPod touch, iPhone4 and iPad. On older devices the “add” icon is a “+” while on iOS 4.2 it has been replaced with
. The script detects the OS version and displays the appropriate icon.
The message appears after 2 seconds (customizable) from page load, and is destroyed after 15 seconds (also customizable). The balloon enters and exits the screen with a quick configurable animation: drop from top, bubble from bottom or fade in/out.
The balloon can be dismissed any time by tapping the small “x” icon.
The script also checks the user’s locale and shows the message in an appropriate language. So far the following languages are supported:
- Catalan
- Chinese (Traditional and Simplified)
- Danish
- Dutch
- English
- Finnish
- French
- German
- Greek
- Hebrew
- Hungarian
- Italian
- Japanese
- Korean
- Norwegian
- Polish
- Portuguese
- Russian
- Spanish
- Swedish
- Thai
- Turkish
Please help me localize the script in more languages.
Locale can be forced, so you can use only English if so desired.
Standard usage
All you need to do for the magic to happen is to add the following inside your page HEAD:
<link rel="stylesheet" href="path/to/add2home.css"> <script type="application/javascript" src="path/to/add2home.js"></script>
That’s it. The code checks the user’s device, OS version, standalone compatibility, etc. If the user is eligible, the screen will be gladden with the cheerful balloon.
Advanced features
You can customize the script behaviors by setting the addToHomeConfig global variable *before* the add2home.js script is included into the page. Let me stress on this. The variable must be globally accessible and must be defined before the script is included inside the page.
Here’s a simple example:
<script type="text/javascript">
var addToHomeConfig = {
animationIn: 'bubble',
animationOut: 'drop',
lifespan:10000,
expire:2,
touchIcon:true,
message:'This is a custom message. Your device is an <strong>%device</strong>. The action icon is `%icon`.'
};
</script>
<script type="application/javascript" src="js/add2home.js"></script>
The popup appears with a bubble effect and is dismissed with a drop animation. It stays on screen for 10 seconds, it is shown only once every 2 minutes, it shows the apple-touch-icon, and changes the default text with a custom one. This is the end result:

Autostart
The script automatically starts on page load. You can prevent this behavior by passing the autostart:false option. You can later show the balloon calling the addToHome.show() public method.
You can also override all the compatibility checks and always show the popup by calling addToHome.show(true). (Not suggested!).
Returning visitors
V2.0 adds the returningVisitor option. This is a very important feature that I highly encourage you to use (ie: set it to true). What it does is to show the message to returning visitors only. The first time a user accesses your site the message is not shown. If the user comes back within a 28 days timeframe, the message is finally presented.
I believe this is very important for usability. When I end up on a new site I just want to look around and there is a very small chance that I will really come back to that site again. But if I come back a second time there’s a good chance that I’ll return a third and a forth.
Showing the message the very first time a user visits your site could be self-defeating and may just irritate her.
More power to the user
If the user intentionally closes the balloon, it won’t show up again for all the duration of that session. This feature overrides all your configurations, even if you set the balloon to show up every single time, if the user taps the close button the message won’t be shown until the browser is closed and reopened.
All the Options
The addToHomeConfig object is used to configure the balloon. The options are:
- autostart: should the balloon be automatically initiated? Default: true.
- returningVisitor: show the message to returning visitors only. Set this to
trueand the message won’t be shown the first time an user visits your site. Default: false. - animationIn: the animation the balloon appears with. Can be:
drop,bubbleandfade. Default: drop. - animationOut: the animation the balloon exits with. Can be:
drop,bubbleandfade. Default: fade. - startDelay: milliseconds to wait before showing the message. Default: 2000
- lifespan: milliseconds to wait before hiding the message. Default: 20000
- bottomOffset: distance in pixels from the bottom (iPhone) or the top (iPad). Default: 14
- expire: minutes before displaying the message again. If you don’t want to show the message at each and every page load, you can set a timeframe in minutes. The message will be shown only one time inside that timeframe. Default: 0 (=always show).
- message: Define a custom message to display OR set a fixed locale. If you don’t like the default message we have chosen for you, you can add your own. You can also force a language by passing the respective locale (eg: ‘en_us’ will always display the English message). Default: ” (=script decides).
- touchIcon: if set to
true, the script checks forlink rel="apple-touch-icon"in the pageHEADand displays the application icon next to the message. Default: false. - arrow: shows the little arrow pointing the bottom bar “add” icon. For custom designs you may want to disable it (ie: set it to
false). Default: true.
Have a look at the many examples to see how the config works.
Public methods
You can programmatically open the balloon by calling the addToHome.show() function.
You can programmatically close the balloon by calling the addToHome.close() function.
During development you may also need to reset the local and session storages. You can do so by calling the addToHome.reset() function.
Change the balloon appearance
Of course you are free to design the balloon in any way you want. Just change the add2home.css file to your likings.
IMPORTANT: UTF-8 forever!
The script contains the “Add to home” message in many languages. To handle English together with Japanese or Hebrew the script has been encoded in UTF-8 (the standard nowadays).
For this reason it is crucial that the JS file is served as UTF-8. That should be default on recent webservers but you can force it by adding the following to your .htaccess:
AddDefaultCharset utf-8 AddCharset utf-8 .html .css .js .xml .json .rss
If you don’t want to convert all your site to UTF-8 you can serve just this script with the proper charset, like so:
<Files "add2home.js"> AddDefaultCharset utf-8 </Files>
(Not tested but should work)
If you can’t modify the .htaccess file, you may want to remove all languages but English from the script.
Web app capable
To prevent the balloon from appearing once the app has been added to the home screen, remember to add the apple-mobile-web-app-capable meta to your page head:
<meta name="apple-mobile-web-app-capable" content="yes">
If your app is not “web app capable”
If you are not willing to add the web-app-capable tag, you can still prevent the balloon from showing up, but there’s no golden rule here. The easiest way is to check for a special url hash. Have a look at the hash-trick example to get an idea, of course this technique modifies the URL the user is going to bookmark (eg: cubiq.org/#ATHS) and it may interfere with other frameworks that use hash-change event. So use it with caution.
The code is and always be MIT licensed, special thanks to all those who helped translating the script!
Hi,
I’m trying to dynamically include your script from within another javascript by injecting the script element into the document head. At the time I include the script, the load and domready events have already fired. I cannot get your script to work, because in this scenario the ready() and loaded() functions will never be called.
Any ideas?
this is a very interesting scenario. I’ll soon release v2.0 that should solve this issue.
Great script, have working fine, but is it possible to alter the default text that appears prior to saving link, or is it only available from the page Title meta?
Thanks for the great scripts and detailed instructions – you’re site is a goldmine for a start-up’s shoe string budget! Donation sent, site bookmarked and knowledge paid forward to others!
Tim, thanks for your support and good luck for your projects!
Fantastic piece of code! Very easy to install and set up.
Thanks for sharing.
iv been struggling to get this script working on any of my sites. can you help?
Can I load this script not on page load, but on button click? If it is posible, can you write short explatation? Thanks.
next version will
if a web page is added once to home page and the same page is loaded on safari will it show the addtohome window or not?
yes, it will. there’s no way to know if an user actually added the page to the homescreen.
Congratulations, great script. When is released the new version?
Most annoying script ever. How do you turn it off? I’m not going to fill my home screen up with web links. This script should be banned as it is invasive and extremely annoying.
Not Impresed!
Wow, I just put it on fyiAuto.com/hot-not?game=Y and added a quick call to our database to track users. I’ve have had over 100 this morning click the add to home screen button. Amazing results. Thank you!
Is there any method to force the user to do the “Add to Home Screen” process? For example to dim the content of the webpage with content?
feasible but it’s out of the script scope.
Great script, it does not seem to work on iOS 5 though. Any thoughts on how to make it work?
I see no issues on iOS5
I’m suddenly not able to turn bookmarks into web apps on my ipad with ios5. I do the same “add to home screen” on the same sites I’ve already done it with and now they all open in Safari. The ones I bookmarked before still open in a web app. Is there some setting on the ipad that’s preventing this from happening? It’s not working on my iphone either.
if the page doesn’t use apple-mobile-web-app-capable it won’t be converted into a web app.
Excellent script, any tips on getting it to work in a sencha touch “afterrender” listener?
Thanks
script is definitely loading, but nothing displayed
You mention: ” there’s no way to know if an user actually added the page to the homescreen.”
Can you not use HTML5 local Web storage for this. I feel users will get a bit sick of this bubble appearing every few minutes even though they have added an icon to their home screen.
you can always display the balloon only once.
How do I do that?
I have set it expire 40 mins but If I can set it to only display once that would be better.
Cheers
set it to something like 525600.
Hi there,
your Script is the best thing ever. I just wanted to know, if it’s possible, to put this Script on a WebSite Mainpage and the Content from the “WebApp” is placed in another subfolder? You know what I mean?
http://www.example.com/index.htm <- Script added
http://www.example.com/ipad/index.htm <- Content after added to Homescreen
Thanks for your help.
Greetings from Germany
Martin
Firstly, Thanks for all your hard work! I am new to programming and just trying to learn. I have the script running in a web app I’m working on but I can’t get the animation to appear just the text. Can you explain where you put the icons and the path to change to get them to appear for a complete beginner please?
Thanks again
Just worked it out! Only problem I am getting is on an iPad and iPhone 4 it adds the “add to home screen” icon instead of the app icon. On my 3gs running ios5 it works fine, any ideas please?
Works really fine on Iphone.
But what is with Android devices?
Do you have a similar solution which also works with Android phones?
I’ll be working on v2 shortly. It will include android support.
Do you already know when it gonna be finished?
Hi. Matteo.
This is what i’v been looking for. However are you able to explain step by step the steps. Iv downloaded the plugin. Intending on putting it on a wordpress theme running a mobile friendly version already.
Where should i place the plugin? what part of the folder?
Where should i edit the code?
Can anyone give me straight forward step by step instructions?
Can you add a cookie when the close button is clicked, preventing the popup for ever showing again (until cookies are deleted)?
use expire option. set it to 1 year.
You are the man!!!
I’ve noticed that when you add the bookmark to your homescreen, it puts a glassy overlay on top of the icon. Can this be avoided?
Thanks,
Bren
Use apple-touch-icon-precomposed
Hi man,
Yes you can:
“In case you realized you don’t like the pre-defined rounded corner plus glossy effect at all, you will have to rename your file (or link rel) accordingly, replacing apple-touch-icon with apple-touch-icon-precomposed. In this way your icon will be rendered as you conceived it, with no further modification.”
So here is the code:
Really cool script. Added it to our bank’s mobile pages and all folks were impressed. Good job.
If you’d find a chance to extend it to Android it would be even greater!
Fantastic! Thank you so much.
Donation and tweets etc are on the way…!
Great script, thanks for sharing! Works perfectly
Great Script!
Another shout for Android support.
BTW How do you add a web app to the Android screen? I can’t see an easy way to do it.
menu > more > add shortcut to home
I too am very interested in the Android version. Thanks so much for this script!!
mythical the scripts perfect and very very simple thank you a lot
I LOVE this script! I wanted to set it to just show on the home page. I looked through the responses here but the fix looked like it was from an earlier version or did not have an answer. If I set “expire” to “1″ it won’t load the script again, even after, say 5 min. I’m kinda new so I am probably missing something elementary, Watson. Any thoughts? Thanks for your work!
Does this work with iScroll? I downloaded it and tried, nothing happend, but an alert(); after everything was loaded appeared.
I will be implementing this in a rails app today- you sire are a life saver/improver!
What could I possibly be missing? Checked all paths, running with iOS 5.01 and won’t work on both an iPhone 4 and iPad 2. Added javascript alerts to the .js file and they pop so I know it’s finding it, but no page displays. Page also uses the iUi framework. Could they perhaps be conflicting?? What about 5.01 iOS? Is that tested? Is the UTF-8 thing required? Can I add that as a META tag to the page instead?
Sorry so many questions but I’m trying to debug this.
Maybe iUI is the culprit. Try to replace
document.body.appendChild(div);
with
document.bodyElement.appendChild(div);
bodyElement did not work. Finally got it to drop now but only by commenting out all the iUi code. There definitely is a conflict and I don’t know how to create a workaround.
Have narrowed it down to a specific CSS setting in the iUi code. Any idea why this conflicts with “Add To home”?
body > *:not(.toolbar) {
display: none;
position: absolute;
margin: 0;
padding: 0;
left: 0;
top: 45px;
width: 100%;
height: auto;
min-height: 415px;
-webkit-transition-duration: 300ms;
-webkit-transition-property: -webkit-transform;
-webkit-transform: translateX(0%);
}
I’ve got the same problem. Trying to implement with iui and the ‘body > *.not(toolbar)’ css breaks it.
That section is fundamental to how iui works, so it’s impossible to change it. It’s how iui hides the different pages and transitions to them.
I’m also using iscroll, but this doesn’t seem to be a problem.
Would be forever grateful if there’s a fix for this!
Cheers, Tony.
Hie, is someone fixed this problem ? Thanks.
Solved it!
Add the class ‘toolbar’ to the add to home javascript and it works. Still some small css issues, but essentially it works.
This is the line in addtohome.js, add the bold bit:
div.className = (isIPad ? ‘ipad’ : ‘iphone’) + (touchIcon ? ‘ wide’ : ”)+ ‘ toolbar’;
Tony
scrap that.
Just use display: block !important; in the addtohome.css
Which CSS line gets this display:block !important;
??
Hey, just try to use our thing: add “display: block !important;” to the #addToHomeScreen and I now have the add to home screen showing
sweet ! But it extends on all the height of the page…. So not the best fix.. If anyone have ideas. I am trying to fix it too
That is very good!
Great plugin man
Hi,
I have a problem;
When opening the front page via the icon on the home screen, all links on this site is opening in a new safari window. That is annoying, not possible to use back button..
Any solution?
You can test it here: http://ledigp.no
This solved my problem; http://stackoverflow.com/questions/2898740/iphone-safari-web-app-opens-links-in-new-window
Following up to post on 11/23… hoping ‘Tony’ can explain exactly which line to put display: in CSS to solve the problem with iUi framework conflict. I got it to work but the text spilled out of the bottom of the balloon so still broken. – Thanks in advance.
Hi,
The fact that the current version can’t be included dynamically makes it impossible for me to use it. You announced a 2.0 version 2 months ago. I do know you are probably doing this in your spare time and this script is a free giveaway. Is there still a chance 2.0 will be out anytime soon?
Michael
Great script ! Thank you !
I will use it for my next wep app
I have only one question : is it possible de change the url shortcut ?
Adress of my web app : domain.com with your script
Adress when the user click on the shortcut : domaine.com/iphone/
Thank you for your help.
How would I get this to work on Blogger?
So cool! I’m running iOS 5 and the height of the box extends all the way to the top of the page. I can’t figure out how to fix that. Any ideas? Thanks so much!!!
Hey, I’ve been using this AWESOME script on a clients site for a while, but I am just now getting around to worrying about the size of the box. I know I can change it in the CSS but is there a way I can just resize the balloon to fit the screen (proportionally appropriate)? Right now, when you load http://www.thejkinz.com it is so small you can hardly read it, is there a way I can resize it without changing every width/height size in the CSS?
I would also like to know how to do this….it would be a great option to add.
Any suggestions?
Hello,
first of all: really nice job!
Now, I’ve got a problem: I’ve got this script working finally but it shows an “Approve” mark when this Add to homescreen script comes up.
I’ve not tested it yet in the english text but i’ll translate:
Install this web app on your %devic(APPROVE MARK)e
so basically:
Install this web app on your iPhon(APPROVE MARK)e
I don’t have any idea how to fix it.
Thx
I’m sorry but I don’t follow you…
Love the script! None of our competitors are doing this. Thanks for helping us be the first!!
Here’s an example of how we are implementing : http://cars.liqueo.com/demo/a_asset_info_WDDGF8BB1CR205262
Love als the script! Good work!
I have a problem such as Ken. Only in this case with jQTouch framework. The script works great without jQTouch code so also in this case there’s something conflicting.
Any solution? Thanks in advance.
Just looking at older posts… stupid.
thank you, this works great!
Nice script!
This script is really nice and easy to use, thanks. You say above that there’s no way to tell if a user has added the app to their home screen yet the FT app somehow knows.
If you visit the app in safari it says “You’ve added the FT Web App to your homescreen but are not using it. Launch the FT Web App from your homescreen to get the best out of it’s features and content.”
Any idea how they can do that?
Thanks a lot for this very interesting script.
Great work Matteo!
I was able to implement it without much trouble at all. I did notice, that once I added the code, the accented characters are not being interpreted correctly. I’m trying to debug it now.
Thank you for sharing!!!