简体   繁体   中英

iOS Facebook App browser - force link to open in Safari

The Facebook App has it's own browser (using the UIWebView for iOS apps) but it has a few limitations. We need certain links on our site to be sure to be viewed with Safari on iOS.

The FB app has an option to manually open links in Safari, but is there a way to do this automatically? Ie. some JS or special parameter in the a tag link to force open in Safari.

well iOS uses something called an URL Scheme so you might be able to try to use that. It works with native code...

NSString *stringURL = @"http://fakewebsite.example.com/";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

not sure if it is possible to do something similar in javascript

There might not be a way to automate this but you should be able to detect it and handle it more gracefully. Facebook adds some extras to the User agent string so you could sniff for some of the FB.. info bits:

Mozilla/5.0 (iPad; U; CPU iPhone OS 5_1_1 like Mac OS X; en_US) AppleWebKit (KHTML, like Gecko) Mobile [FBAN/FBForIPhone;FBAV/4.1.1;FBBV/4110.0;FBDV/iPad2,1;FBMD/iPad;FBSN/iPhone OS;FBSV/5.1.1;FBSS/1; FBCR/;FBID/tablet;FBLC/en_US;FBSF/1.0]

There seems to be some people trying to figure out what they mean, but regardless they tell you that you're within that facebook web frame.

Sniffing (js or backend) for one of these would allow you to load the page differently or at least display an explanation and instructions to open it in safari. Still not automatic but you can at least detect the situation and have a documented manual solution.

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