Skip to main content

[Titanium Mobile] Webview canGoBack returning false

剛好 Titanium Mobile Forum 上有人詢問了有關 webview goBack的問題

問題是當 WebView 第一頁為 local web page or html 時點選網頁上的超連結到下個頁面,這時用 button click 去判定 WebView 的 canGoBack 來處理 WebView.goBack() or win.close() 如下:

if(webview.canGoBack()){
webview.goBack();
}
else{
win.close();
}

這時候會收到回傳 false 造成 win.close() 而無法利用 WebView.goBack() 回到原始的頁面...

解法很間單,只需要在 WebView 初始時設定轉址至初始的 local web page 即可解決。

var webview = Ti.UI.createWebView({
html: 'html><head><meta http-equiv="refresh" content="0;url=index.html" /></head><body></body></html>'
});

Comments

Popular posts from this blog

[書評] 拖延心理學:為什麼我老是愛拖延?是與生俱來的壞習慣,還是身不由己?

作者: Jane B. Burka & Lenora M . Yuen 推薦指數 ★★★★★ 有時候,只是想了解事情發生原因而不是尋求解法 在這邊不是要講這本書的內容,而是想聊它對我的影響。