简体   繁体   中英

is there no way to detect webview (chrome/android) with client side language?

I've figured out how to detect when my page is loaded on mobile in webview, but only for iOS with:

var standalone = window.navigator.standalone,
uerAgent = window.navigator.userAgent.toLowerCase(),
safari = /safari/.test( userAgent ),
ios = /iphone|ipod|ipad/.test( userAgent );

I've researched and it seems like chrome/android has to be done on the server side - do anyone know whether it is possible with JS to detect whether website is opened within webview on chrome/android? For example when your website is opened up within Facebook?

You can set a custom string as user-agent in your app's WebView.So if the user-agent is the custom string,you know that now it's in your app's WebView.

Android:

webView.getSettings().setUserAgentString("your agent");

iOS:

NSUserDefaults.standardUserDefaults().registerDefaults(["UserAgent": "your agent"])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM