Android Webview:有没有办法知道以前的URL是什么?

时间:2011-10-18 21:22:15

标签: android webview back browser-history

有没有办法访问历史记录,以便我知道用户点击后退按钮(调用WebView.goBack())时访问的URL?

2 个答案:

答案 0 :(得分:23)

String historyUrl="";
myWebView = (WebView) findViewById(R.id.webViewContent);
WebBackForwardList mWebBackForwardList = myWebView.copyBackForwardList();
if (mWebBackForwardList.getCurrentIndex() > 0) 
    historyUrl = mWebBackForwardList.getItemAtIndex(mWebBackForwardList.getCurrentIndex()-1).getUrl();

// Previous url is in historyUrl

答案 1 :(得分:16)

这可能是您正在寻找的方法:WebView.copyBackForwardList