Reputation: 3389
I have a link on my mobile app (created with Sencha Touch 2) with a target="_blank"
attribute. The app is packaged as a native iOS app. The problem is, the link is not opening in Safari as expected, instead it opens inside the app. It is very important that the link opens in Safari in a new browser window. How can I achieve that?
I should add that I am using the native packager of Sencha (sencha package). The default behaviour seems to open the new window in the same webview. But I need them to be opened in mobile Safari.
In an Xcode project I could do the following:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
}
return YES;
}
How to do that with Sencha Touch native packaging?
Upvotes: 2
Views: 6503
Reputation: 2460
Programmatically (Javascript) opens a link in Mobile Safari. Ideal if you cannot use a standard html link but you must use Javascript:
var a = document.createElement("a");
a.setAttribute('href', facebook);
a.setAttribute('target', '_blank');
a.click();
Upvotes: 1
Reputation: 81
I use this to open links in either Mobile Safari, or a new window. Works with Native iOS packaging and web apps:
function externalLink(link) {
try{
Ext.device.Device.openURL(link);
}catch(err) {
window.open(link, '_blank');
}
}
Upvotes: 8
Reputation: 799
I haven't discovered a way to do this with sencha native packaging.
But wrapping the application in a phonegap and compiling the application in Xcode, with required urls added to the ExternalHost array in phonegap.plist should work right?
Also, (still on the Phonegap solution) I assume hacking AppDelegate.m to open links in Safari would work just as fine.
Upvotes: 3