[英]How do I detect, via javascript in Safari Mobile, if my iPhone application is installed?
[英]can I detect a user on Mobile Safari (iphone) VS UIWebView (WebKit) with javascript?
我希望能夠分辨出在iPhone或ipad上通過普通Safari瀏覽我的網站的用戶與通過本機iOS應用中的UIWebView點擊相同內容的用戶之間的區別。
我希望有一種使用javascript和用戶代理字符串的方法? 朝正確方向進行進一步調查的任何觀點將不勝感激!
謝謝!
我建議您在本機iOS應用程序的URL字符串中發送GET變量,並將該值保存到Web服務器上的會話變量中。 然后使用會話變量為Mobile Safari和UIWebview做不同的事情
當您請求網站時,在iOS應用中添加“獲取變量”
的iOS
NSString *urlQueryString = @"?BrowserType=iOSNative";
NSString *URLPath = [NSString stringWithFormat:@"http://www.yoursite.com/%@",urlQueryString ];
NSURL *requestURL = [NSURL URLWithString:URLPath];
NSURLRequest *request = [NSURLRequest requestWithURL:requestURL];
[self.webview loadRequest:request];
的PHP
if(isset($_REQUEST['BrowserType']))
{
//Used for tracking is this is an iOS Native App user.
//This will not be set by the mobile browser user
$browserType = filter_var($_REQUEST['BrowserType'], FILTER_SANITIZE_STRING);
$_SESSION['BrowserType']=$browserType;
}
if ($_SESSION['BrowserType']=="iOSNative")
{
echo 'This is the native App and shouldn't display on the mobile page';
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.