Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  88] [ 2]  / answers: 1 / hits: 23198  / 9 Years ago, thu, august 6, 2015, 12:00:00

I have an html-javascript page, and I need to detect whenever it open on web view (Like inside facebook webview, twitter webview, etc.), and if it a webview - display another content.



Note: I do not control the third-party Android apps, so I cannot make changes to their code.



I already found a way to detect an IOS webview (Found it on stackoverflow):



var isIosWebview =/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent)



Now I'm looking for a javascript code that can detect Android web view.



Help?


More From » android

 Answers
3

You can't detect it by only using the user agent string, as any app that uses WebView can set the UA string to anything it wants.



If you still insist on using the UA string, this is the explanation of the official docs: initially, Chromium-based WebView was using .0.0.0 as Chrome version suffix; in the newer versions ; wv was added into the platform part of the UA string. Note that pre-KitKat WebViews didn't have the Chrome part. See older posts about that: Android, webview user agent vs browser user agent



Another hint of WebView involvement is presence of X-Requested-With HTTP header with an application package name. Note that this header is also set by XMLHttpRequest, so you need to look for the actual value of the header.



The statement that WebView doesn't support iframes is not correct.


[#65523] Tuesday, August 4, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brodyfrancisi

Total Points: 1
Total Questions: 102
Total Answers: 89

Location: Marshall Islands
Member since Mon, May 31, 2021
3 Years ago
brodyfrancisi questions
;