Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detecting UIWebView with Javascript [duplicate]

Is there a way to detect with JavaScript if the website runs inside the iPad's Safari or inside an application WebView?

like image 480
sod Avatar asked Aug 13 '26 01:08

sod


1 Answers

This uses a combination of window.navigator.userAgent and window.navigator.standalone. It can distinguish between all four states relating to an iOS web app: safari (browser), standalone (fullscreen), uiwebview, and not iOS.

Demo: http://jsfiddle.net/ThinkingStiff/6qrbn/

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 ) {
        //browser
    } else if ( standalone && !safari ) {
        //standalone
    } else if ( !standalone && !safari ) {
        //uiwebview
    };
} else {
    //not iOS
};
like image 91
ThinkingStiff Avatar answered Aug 15 '26 14:08

ThinkingStiff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!