Stackoverflow - detect ipad/iphone webview via javascript
http://stackoverflow.com/q/4460205/918414
by Craig Martin
HTML
<div id="where-am-i"></div>
<script>
/* by: thinkingstiff.com
license: http://creativecommons.org/licenses/by-nc-sa/3.0/us/ */
var headerUri = 'http://stackoverflow.com/q/4460205/918414',
headerCaption = 'detect ipad/iphone webview via javascript';
document.body.insertAdjacentHTML(
'afterBegin',
'<a href="' + headerUri + '" '
+ 'target="_top" '
+ 'onmouseover="this.style.opacity=\'.95\'" '
+ 'onmouseout="this.style.opacity=\'1\'" '
+ 'style="'
+ 'background-color: black;'
+ 'background-image: linear-gradient( top, rgba( 255, 255, 255, .3), rgba( 255, 255, 255, 0) );'
...
JavaScript
var standalone = window.navigator.standalone,
userAgent = window.navigator.userAgent.toLowerCase(),
safari = /safari/.test( userAgent ),
ios = /iphone|ipod|ipad/.test( userAgent );
if( ios ) {
if ( !standalone && safari ) {
document.getElementById( 'where-am-i' ).textContent = 'browser '+standalone+" "+userAgent;
} else if ( standalone && !safari ) {
document.getElementById( 'where-am-i' ).textContent = 'standalone';
} else if ( !standalone && !safari ) {
document.getElementById( 'where-am-i' ).textContent = 'uiwebview';
};
} else {
document.getElementById( 'where-am-i' ).textContent = 'not iOS '+standalone+" "+userAgent+" "+safari;
};