我正在使用PhoneGap为iPad编写应用程序,并希望加载外部URL而不触发Safari或使用内部Web浏览器(如ChildBrowser)。
我正在使用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 容器中打开链接,这很好。但我的问题是我想要加载用 Python 编写的动态页面
loadHTML('http://www.mysite.com/cgi-bin/index.py',10000)
此时,在PhoneGap容器中显示了一个黑色页面,但尚未调用Safari浏览器!我想指出的是,如果我在Safari中键入该链接,则链接完全有效(由于隐私问题,我无法报告它)。
这可能与某种所需权限有关吗?
我找到了一些与BlackBerry的PhoneGap相关的类似情况,并提出了通过修改config.xml文件来解决的建议。
<access subdomains="true" uri="http://www.mysite.com/" />
我尝试直接在我的index.html文件中添加此标签,但它没有起作用。
是否有类似的方法适用于iPhone?
非常感谢。