Last active
December 10, 2015 21:18
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! 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); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! 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