我正在使用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 …