我正在使用PhoneGap编写iPad应用程序,我想加载外部URL而不触发Safari或使用像ChildBrowser这样的内部Web浏览器.
我正在使用PhoneGap iPad/iPhone示例项目,我尝试了不同的方法.在onBodyLoad()函数中,我添加了:
window.location.href('http://www.wordreference.com');
Run Code Online (Sandbox Code Playgroud)
但是这一行使用一个新的Safari窗口打开链接.从那时起,无法返回PhoneGap
之后,我尝试使用document.write替换页面内容的AJAX请求
function loadHTML(url, timeout) {
if (timeout == undefined)
timeout = 10000;
var req = new XMLHttpRequest();
var timer = setTimeout(function() {
try {
req.abort();
} catch(e) {}
navigator.notification.loadingStop();
},timeout);
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status < 300) {
clearTimeout(timer);
var html = req.responseText;
//just a debug print
alert(html);
document.write(html);
}
navigator.notification.loadingStop();
delete req;
}
};
req.open('GET', url, true);
req.send();
}
Run Code Online (Sandbox Code Playgroud)
现在,从onBodyLoad()内部调用:
loadHTML('http://www.wordreference.com',10000);
Run Code Online (Sandbox Code Playgroud)
打开PhoneGap容器中的链接,没问题.关键是我想加载用Python编写的动态页面
loadHTML('http://www.mysite.com/cgi-bin/index.py',10000)
Run Code Online (Sandbox Code Playgroud)
此时未调用Safari,但会显示PhoneGap容器中的黑色页面!我想指出,如果我在Safari中键入它,链接就完全正常工作(我无法报告隐私问题).
可能是与某种必要的许可有关的问题???
我找到了与PhoneGap for …
好的,浏览问题我找到了将外部页面加载到phonegap视图的正确方法(即不丢失会话或打开设备浏览器),如下所述:如何在phonegap webview中加载网页? 在这里:iPhone的PhoneGap:加载外部URL的问题
下一步是:在我打开一个extarnal页面(它由我拥有并且我可以修改它)后,我怎么能回到我的本地应用程序?假设我在外部页面中有一个链接,我希望用户在单击时重定向回到phonegap应用程序内的本地html页面(mypage.html).
链接的href属性应该包含哪些URL?我已经尝试将其设置为"file:///android_asset/www/mypage.html"但是没有用
我正在处理应用程序,它将处理一些特定于设备的事情,但随后将用户重定向到在线网页.这在iOS版本中运行良好,我试图让它在Android中运行.
目前在Android中,该应用程序会加载,但如果我有一个window.location.href = ...电话,则无效window.onload.iOS必需的设置之一是OpenAllWhitelistURLsInWebView.Android有类似的设置吗?你怎么设置它?还有其他建议吗?