【发布时间】:2013-04-13 12:55:40
【问题描述】:
我尝试像这样打开外部网址,
<a href="http://google.com" target="_system" >
也可以尝试使用_blank,但它在同一个应用程序屏幕中打开,而不是在 safari 浏览器中打开,
如何解决..?
【问题讨论】:
我尝试像这样打开外部网址,
<a href="http://google.com" target="_system" >
也可以尝试使用_blank,但它在同一个应用程序屏幕中打开,而不是在 safari 浏览器中打开,
如何解决..?
【问题讨论】:
如果您更改链接以使用新的 InAppBrowser 语法,则可以轻松地在系统 Web 浏览器、InAppBrowser 或应用的实际 Web 视图中打开您的 URL。
此代码应在系统网络浏览器(iOS 上的 Safari)中打开您的 URL:
<a href="#" onclick="var ref = window.open('http://google.com', '_system');">
将 '_system' 更改为 '_blank' 将在 InAppBrowser 中打开 URL。
将'_system' 更改为'_self' 将在您的应用(如果域被列入白名单)或InAppBrowser(如果域未被列入白名单)的webview 中打开该URL。
示例要点:https://gist.github.com/wicketyjarjar/7043336
注意:Cordova/PhoneGap 3.0+ 需要安装 InAppBrowser 插件才能工作。
安装 InAppBrowser 插件(如有必要)...
使用 Cordova:cordova plugin add org.apache.cordova.inappbrowser
使用PhoneGap:phonegap local plugin add org.apache.cordova.inappbrowser
【讨论】:
我的解决方案如下: 首先我定义一个函数来打开 safary url:
LaunchNewWindow: function (url) {
if (window.location.toStringing().match(/file/i) && navigator.userAgent.match(/iPhone|iPad|iPod/i) ) {
window.open(url+"_xex_", "_blank");}
else{
window.open(url, "_blank");
}
}
那么您必须更改 CordovaLic\Classses\CDViewController.m (CordovaLib 3.0.0) 中的代码来处理您的空间网址: 我在第 685 行添加了它:
else {
// start stoneskin's change: force open external url in safari
if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
NSString *myurlstr = [url absoluteString];
if ([myurlstr rangeOfString:@"_xex_"].location != NSNotFound){
myurlstr = [myurlstr stringByReplacingOccurrencesOfString:@"_xex_" withString:@""];
NSURL *myurl = [NSURL URLWithString:myurlstr];
[[UIApplication sharedApplication] openURL:myurl];
return NO;
}
}
//end start stoneskin's change
if ([self.whitelist schemeIsAllowed:[url scheme]]) {
return [self.whitelist URLIsAllowed:url];
} else {
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
} else { // handle any custom schemes to plugins
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
}
}
return NO;
}
【讨论】: