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?
@ Sod, Well i don’t have answer, but i am not convinced why you want to check, Since, browser engine whether its safari ( Browser ) or Application will be same its Webkit only, Yes Application can configure the Browser engine capabilities like, whether application wants to run JS or Display Image etc…
I believe, you must check for certain property whether Flash supported by Browser or whether browser displays image or not, or probably may be you would like to check the screen size,
I've tried all these solutions but didn't work in my case,
I was going to detect Telegram inside Webview. I've noticed Safari is changing phone style text to a link with "tel:" prefix, so I've used this to write this code, you can test it : jsfiddle
I don't think there's anything specific you can use in client-side Javascript, but if you have control over what the originating UIWebView can do, you might want to consider playing with the user agent string it generates, and testing for that in your client-side Javascript instead? A bit of a hack I know, but hey… This question may give some pointers on tweaking the user agent:
Change User Agent in UIWebView (iPhone SDK)
I know this code will check if it is being accessed from an icon added to the home screen:
but I'm not sure how it would react in a UIWebView. The only other solution I could think of is getting the user agent or using
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
and replacing the query string of the page you are accessing with something the page uses to identify that it is being accessed from a web view.Would suggest using Modernizr, and checking for indexeddb like this. You could cross-check that with user agent configuration (device, OS, browser, etc), but pure feature detection seems more recommended.
I have found a simple solution to detect iPhone or iPad. This works for me fine.