Javascript 在PhoneGap中调用window.location.href会触发web浏览器
你好 我正在尝试使用PhoneGap为iPad开发一个应用程序。我想在index.html页面内直接加载外部网站的主页。 不幸地使用Javascript 在PhoneGap中调用window.location.href会触发web浏览器,javascript,ipad,browser,cordova,window.location,Javascript,Ipad,Browser,Cordova,Window.location,你好 我正在尝试使用PhoneGap为iPad开发一个应用程序。我想在index.html页面内直接加载外部网站的主页。 不幸地使用 window.location.href = "http://mywebsite.com/cgi-bin/index.py" 触发Safari窗口的打开,而不是使用PhoneGap容器 有什么建议吗 非常感谢 Claus在项目的“类”部分找到AppDelegate.m文件,并找到webView:shouldStartLoadWithRequest:navigat
window.location.href = "http://mywebsite.com/cgi-bin/index.py"
触发Safari窗口的打开,而不是使用PhoneGap容器
有什么建议吗
非常感谢
Claus在项目的“类”部分找到AppDelegate.m文件,并找到webView:shouldStartLoadWithRequest:navigationType 使函数看起来像这样,然后重试
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}
else {
return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
}
}
有一个更简单的选项:modify config.xml 在WebView中打开所有链接 使用true或false值停留在webview中
- 示例:
- 如果设置为true,所有链接(即使目标设置为空)都将在应用程序的webview中打开
- 仅当您希望服务器上的页面接管整个应用程序时,才使用此首选项
- 默认值为false
来源:另一个问题的答案是正确的:答案可以在这里找到: