【发布时间】:2011-05-06 12:15:01
【问题描述】:
我正在使用 PhoneGap 为 iPad 编写应用程序,我想在不触发 Safari 或使用 ChildBrowser 等内部网络浏览器的情况下加载外部 URL。
我正在使用 PhoneGap iPad/iPhone 示例项目,并尝试了不同的方法。在我添加的 onBodyLoad() 函数中:
window.location.href('http://www.wordreference.com');
但此行使用新的 Safari 窗口打开链接。从那时起,无法在 PhoneGap 中返回
之后,我尝试使用 AJAX 请求替换页面内容,使用 document.write
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();
}
现在,从 onBodyLoad() 内部调用:
loadHTML('http://www.wordreference.com',10000);
在 PhoneGap Container 中打开链接,这很好。重点是我要加载一个用Python写的动态页面
loadHTML('http://www.mysite.com/cgi-bin/index.py',10000)
此时 Safari 没有被调用,但在 PhoneGap 容器中显示了一个黑页!! 我想指出,如果我在 Safari 中键入该链接,它就可以正常工作(我不能报告它的隐私问题)。
可能是与某种所需权限有关的问题???
我发现了与 PhoneGap for BlackBerry 类似的东西,建议的解决方案是使用
修改 config.xml 文件<access subdomains="true" uri="http://www.mysite.com/" />
我尝试将这个标签直接添加到我的 index.html 中,但它不起作用。
iPhone 有没有类似的方法?
非常感谢
【问题讨论】:
标签: load cordova window.location external-links