javascript - 在 PhoneGap 中打开新窗口/文档

标签 javascript html cordova

使用以下代码,我可以在桌面浏览器上打开一个新窗口:

            var thisWin = window;
            var oauthWin = thisWin.open(data, 'twitter-oauth-window', 'location=0,status=0,width=800,height=400');
            var lastUrl = oauthWin.location.href;
            var meh = true;
            var oauthInt = thisWin.setInterval(
              function()
              {
                if (meh)
                {
                  alert(
                    '\noauthWin.closed: ' + oauthWin.closed +
                    '\noauthWin.location: ' + oauthWin.location +
                    '\nthisWin.closed: ' + thisWin.closed +
                    '\nthisWin.location: ' + thisWin.location +
                    '\noauthWin===thisWin: ' + (oauthWin === thisWin));
                  meh = false;
                }
                // do more stuff here
              }
            );

在警报内的调试输出中:

 oauthWin===thisWin: false

这是应该的。但是,当在 PhoneGap 中运行相同的代码时,我得到以下结果:

 oauthWin===thisWin: true

这表明 PhoneGap 已在同一窗口中打开新的 URL,替换当前的 HTML 文档。

我希望单独打开新的 URL,并能够在满足特定条件时关闭它,并恢复到旧的 URL。

这可以在 PhoneGap 中实现吗?如何实现?

谢谢!

最佳答案

现在使用 PhoneGap 2.3+,我无法以任何方式在 Mobile Safari 中打开 URL。使用 _blank 不起作用,我尝试了 window.open(url, '_blank'),但是现在使用 InAppBrowser 插件打开 URL(这非常糟糕)。我觉得很有趣的是,它使用了一个插件,所以我决定编写一个插件来使用在 iOS 应用程序中打开 URL 的标准方法来打开 URL。您可以在 this gist here: https://gist.github.com/typeoneerror/5097118 上查看/获取代码.

这很简单。在我的示例中,我使用 jQuery 连接了具有名为“_blank”的类的链接,并使用插件调用打开了这些 URL:

// execute the plugin called OpenUrl, signature:
// exec(successCallback, errorCallback, pluginName, pluginMethod, params)
cordova.exec(success, error, "OpenUrl", "openUrl", [url]);

我确信您可以轻松地为您需要的每个平台重写该插件。这是 iOS 特定的。

关于javascript - 在 PhoneGap 中打开新窗口/文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11699163/

相关文章:

php - 水平显示超出页面宽度的父div

javascript - 如何将 javascript 变量输入到 php 脚本中?

android - 仅在安装时在 phonegap android 应用程序中创建数据库

java - 移动/复制捕获的图像phonegap android中的问题

javascript - react : 404 Found when importing local images

javascript - 手机间隙 : Resolving content://URI obtained from native file chooser

jquery-mobile - Phonegap 和 jquery mobile : a href -> Origin null is not allowed by Access-Control-Allow-Origin

javascript - 当输入无效时如何禁用表单提交 anchor ?

javascript - 使用字典作为D3数据源