Skip to content

Instantly share code, notes, and snippets.

@mockee
Created December 19, 2012 10:11
Show Gist options
  • Save mockee/4335716 to your computer and use it in GitHub Desktop.
Save mockee/4335716 to your computer and use it in GitHub Desktop.
define(function() {
var bodyTag
, win = window
, doc = document
, docElement = doc.documentElement
function hideAddressBar(isPad) {
if (screen.width > 980 || screen.height > 980) { return }
if (win.navigator.standalone === true) { return }
// Page zoom or vertical scrollbars
if (win.innerWidth - docElement.clientWidth > 1) { return }
if (isPad === true
&& (docElement.scrollHeight <= docElement.clientHeight)) {
// Extend body height to overflow and cause scrolling
bodyTag = doc.getElementsByTagName('body')[0]
// Viewport height at fullscreen
bodyTag.style.height = docElement.clientWidth
/ screen.width * screen.height + 'px'
}
setTimeout(function() {
if (win.pageYOffset !== 0) { return }
win.scrollTo(0, 1)
// Reset body height and scroll
if (bodyTag !== undefined) {
bodyTag.style.height = win.innerHeight + 'px'
}
win.scrollTo(0, 0)
}, 600)
}
if (win.addEventListener) {
win.addEventListener('orientationchange', hideAddressBar)
}
return hideAddressBar
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment