Is there a way to differ via javascript if the website runs inside the ipad safari or inside an application WebView?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Yeah:
Neoneye's solution does not work anymore (see comments) and can be simplified. On the other hand, testing only "Safari" in the UA adresses much more than the ios handheld devices.
This is the test i'm using :
I think that you can just use the
User-Agent
.UPDATE
Page browsed using iPhone Safari
I will try in a second with UIWebView
The difference is that the Safari one says
Safari/6531.22.7
Solution
User Agents
Running in UIWebView
Running in Safari on iPad
Running in Safari on Mac OS X
Running in Chrome on Mac OS X
Running in FireFox on Mac OS X
Detection Code
This uses a combination of
window.navigator.userAgent
andwindow.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/
Last time I needed this (JUST for WebView purposes), I used this check: