├── README.md ├── jquery.stayInWebApp.js └── jquery.stayInWebApp.min.js /README.md: -------------------------------------------------------------------------------- 1 | This jQuery plugin will stop links from leaving full screen mode on iOS devices. Other side effects may be included. 2 | 3 | $(function() { 4 | $.stayInWebApp(); 5 | }); 6 | 7 | This use only links with the class `stay`. 8 | 9 | $(function() { 10 | $.stayInWebApp('a.stay'); 11 | }); 12 | 13 | Full links (starting with http) will still open in Safari, as well as links with `target="_blank"`. 14 | 15 | - - - - - - - - - - 16 | 17 | Thanks to [Bryan Murdaugh and David Leininger](http://fivable.com) for the original starting script (mostly for discovering that self.location works). 18 | 19 | Thanks to Ben Nadel for posting about how to [detect iOS full screen mode](http://www.bennadel.com/blog/1950-Detecting-iPhone-s-App-Mode-Full-Screen-Mode-For-Web-Applications.htm). -------------------------------------------------------------------------------- /jquery.stayInWebApp.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * jQuery stayInWebApp Plugin 3 | * version: 0.4 (2012-06-19) 4 | */ 5 | 6 | ;(function($) { 7 | //extend the jQuery object, adding $.stayInWebApp() as a function 8 | $.extend({ 9 | stayInWebApp: function(selector) { 10 | //detect iOS full screen mode 11 | if(("standalone" in window.navigator) && window.navigator.standalone) { 12 | //if the selector is empty, default to all links 13 | if(!selector) { 14 | selector = 'a'; 15 | } 16 | //bind to the click event of all specified elements 17 | $("body").delegate(selector,"click",function(event) { 18 | //TODO: execute all other events if this element has more bound events 19 | /* NEEDS TESTING 20 | for(i = 0; i < $(this).data('events'); i++) { 21 | console.log($(this).data('events')); 22 | } 23 | */ 24 | 25 | //only stay in web app for links that are set to _self (or not set) 26 | if($(this).attr("target") == undefined || $(this).attr("target") == "" || $(this).attr("target") == "_self") { 27 | //get the destination of the link clicked 28 | var dest = $(this).attr("href"); 29 | 30 | //if the destination is an absolute url, ignore it 31 | if(!dest.match(/^http(s?)/g)) { 32 | //prevent default behavior (opening safari) 33 | event.preventDefault(); 34 | //update location of the web app 35 | self.location = dest; 36 | } 37 | } 38 | }); 39 | } 40 | } //end stayInWebApp func 41 | }); 42 | })( jQuery ); -------------------------------------------------------------------------------- /jquery.stayInWebApp.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * jQuery stayInWebApp Plugin 3 | * version: 0.4 (2012-06-19) 4 | */ 5 | (function($){$.extend({stayInWebApp:function(b){"standalone"in window.navigator&&window.navigator.standalone&&(b||(b="a"),$("body").delegate(b,"click",function(b){if($(this).attr("target")==void 0||$(this).attr("target")==""||$(this).attr("target")=="_self"){var c=$(this).attr("href");if(!c.match(/^http(s?)/g))b.preventDefault(),self.location=c}}))}})})(jQuery); --------------------------------------------------------------------------------