Skip to content

Instantly share code, notes, and snippets.

@ptb
Last active December 10, 2015 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptb/4494626 to your computer and use it in GitHub Desktop.
Save ptb/4494626 to your computer and use it in GitHub Desktop.
On iPhone and iPod touch, automatically hide Mobile Safari's URL text field on page load, orientation changes, and resize.
/*! gist.github.com/4494626 | (c) 2013 Peter T Bosse II | Apache license */
/*jshint camelcase:true, curly:true, eqeqeq:true, quotmark:single, unused:true, laxbreak:false, onevar:true, latedef:true, trailing:true, indent:2, white:true, strict:true, browser:true, devel:true, jquery:true, prototypejs:true, undef:true */
(function () {
'use strict';
// Inspired by: <http://www.apress.com/9781430230458>
// Beginning iPhone & iPad Web Apps: Scripting with HTML5, CSS3, & JS
// Chapter 4: Pages 85-86: Hiding Mobile Safari's Address Bar
// Inspired by: <http://bit.ly/drwur7>
// Doing It Right: Hiding the iPhone URL Text Field
function hideURLTextField() {
if (/iP(hone|od)/.test(navigator.platform) && !navigator.standalone) {
document.body.style.height = (window.innerHeight + 60) + 'px';
window.setTimeout(function () {
window.scrollTo(window.pageXOffset, window.pageYOffset);
document.body.style.height = window.innerHeight + 'px';
}, 0);
}
}
document.addEventListener('DOMContentLoaded', hideURLTextField, 0);
window.addEventListener('orientationchange', hideURLTextField, 0);
window.addEventListener('resize', hideURLTextField, 0);
})();
/*! gist.github.com/4494626 | (c) 2013 Peter T Bosse II | Apache license */
(function(){'use strict';function a(){/iP(hone|od)/.test(navigator.platform)&&!navigator.standalone&&(document.body.style.height=window.innerHeight+60+'px',window.setTimeout(function(){window.scrollTo(window.pageXOffset,window.pageYOffset),document.body.style.height=window.innerHeight+'px'},0))}document.addEventListener('DOMContentLoaded',a,0),window.addEventListener('orientationchange',a,0),window.addEventListener('resize',a,0)})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment