Javascript 在PhoneGap中打开新窗口/文档
使用以下代码,我可以在桌面浏览器上打开一个新窗口:Javascript 在PhoneGap中打开新窗口/文档,javascript,html,cordova,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 = tru
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。你可以在上面看到/抓取代码 这很简单。在我的示例中,我用jQuery连接了一个名为“\u blank”的类的链接,并用插件调用打开了这些URL:
// execute the plugin called OpenUrl, signature:
// exec(successCallback, errorCallback, pluginName, pluginMethod, params)
cordova.exec(success, error, "OpenUrl", "openUrl", [url]);
我相信你可以很容易地为你需要的每个平台重写插件。这是iOS特有的