PhoneGap:无法加载外部网站

发布于 2024-12-25 18:13:52 字数 533 浏览 2 评论 0原文

我正在尝试在 PhoneGap 应用程序中显示一个页面,例如 www.google.com。但是,我无法在 Safari 中打开页面,更不用说在 PhoneGap 中(这是我的最终目标)。

我看到这篇文章:PhoneGap for iPhone:加载外部 URL 时出现问题,并尝试了以下操作:

-如该问题的解决方案中所述,我修改了我的 AppDelegate.m 文件。

- 完成此操作后,在 index.html 文件(由 PhoneGap 创建)的一部分中,我有以下代码:

window.location("http://google.com");

虽然项目编译和构建良好,但我只看到一个空白页面。

我将不胜感激任何帮助,谢谢。

I'm trying to display a page, for example, www.google.com, in a PhoneGap application. However, I can't get the page to open in Safari, much less within PhoneGap (which is my ultimate goal).

I saw this post: PhoneGap for iPhone: problem loading external URL, and have tried from it the following:

-As described in the solution to that question, I have modified my AppDelegate.m file.

-After doing this, in part of the index.html file (created by PhoneGap), I have this code:

window.location("http://google.com");

Although the project compiles and builds fine, I see only a blank page.

I would appreciate any help, thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷迭香的记忆 2025-01-01 18:13:52
window.location("http://google.com");

不是有效的 JavaScript。您需要:

window.location.replace("http://google.com");

window.location.href="http://google.com";
window.location("http://google.com");

isn't valid JavaScript. You need:

window.location.replace("http://google.com");

or

window.location.href="http://google.com";
天暗了我发光 2025-01-01 18:13:52

使用 .href 并查看此帖子,了解有关 PhoneGap 和外部 URL 的更多信息:PhoneGap for iPhone:加载外部 URL 时出现问题

Use .href and check this post for more information about PhoneGap and external URL: PhoneGap for iPhone: problem loading external URL

乖乖 2025-01-01 18:13:52

你需要的是 MainViewController.m 中的这个魅力,它适用于cordova 1.7.0 cordova 1.9.0 和 cordova 2.1.0

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request   navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];

// Intercept the external http requests and forward to Safari.app
// Otherwise forward to the PhoneGap WebView
if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
    [[UIApplication sharedApplication] openURL:url];
return NO;
}
else {
return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
}
    }

What you need is this charmer in your MainViewController.m It works for me in cordova 1.7.0 cordova 1.9.0 and cordova 2.1.0

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request   navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];

// Intercept the external http requests and forward to Safari.app
// Otherwise forward to the PhoneGap WebView
if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
    [[UIApplication sharedApplication] openURL:url];
return NO;
}
else {
return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
}
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文