我正在爲使用PhoneGap的iPad編寫應用程序,並且希望加載外部網址而不觸發Safari或使用內部網絡瀏覽器(如ChildBrowser)。PhoneGap for iPhone:加載外部URL時出現問題
我正在使用PhoneGap iPad/iPhone示例項目,並嘗試了不同的方法。在onBodyLoad()函數我說:
window.location.href('http://www.wordreference.com');
,但此行開啓使用新的Safari瀏覽器window.From這一點是不可能的鏈接回來的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)
在這一點上的Safari不叫,但顯示在PhoneGap的容器中的黑頁! 我想指出,如果我在Safari中輸入鏈接,我的鏈接完全可以正常工作(我無法報告它的隱私問題)。
可能是與某種需要的權限有關的問題???
我發現了類似的相對的東西的PhoneGap黑莓和所提出的解決方案是修改與
<access subdomains="true" uri="http://www.mysite.com/" />
一個config.xml文件我想直接在我的index.html添加此標籤,但它不工作。
iPhone有沒有類似的方法?
非常感謝
好極了!這是在應用程序內部保留window.location.href =''命令的正確答案。 – davidethell 2011-12-28 00:13:29
之後如何導航迴應用程序? – 2012-10-26 12:13:17
太棒了,謝謝你。請注意,從1.6開始,您需要在MainViewController.m中查找此方法。 – 2013-06-20 14:54:54