Narayan soni
Narayan soni

Reputation: 821

How to handle html back in webview android

I am using webview to show one html page in this page i have one button, through this button click i am navigating to another webpage, on that webpage have one hyperlink for go back but when i try with this code

<a href="#backButton" onclick="window.history.back();">Go back</a> 

but not able to show previous page so, please suggest me can i get any event of hyperlink on my activity or any other suggestion to show previous page without pressing back button of device

Upvotes: 1

Views: 3113

Answers (2)

Narayan soni
Narayan soni

Reputation: 821

I have solved this issue with replace with

<a href="#backButton" onclick="window.history.back();">Go back</a> 

to

<a href="#backButton" onclick="window.history.back();return false">Go back</a> 

now its works fine

Upvotes: 2

Rushabh Patel
Rushabh Patel

Reputation: 3080

You can use this code mentioned below:

WAY-1

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(event.getAction() == KeyEvent.ACTION_DOWN){
        switch(keyCode)
        {
        case KeyEvent.KEYCODE_BACK:
            if(mWebView.canGoBack() == true){
                mWebView.goBack();
            }else{
                finish();
            }
            return true;
        }

    }
    return super.onKeyDown(keyCode, event);
}

WAY-2

@Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    if(mWebView.canGoBack() == true){
        mWebView.goBack();
    }else{
        super.onBackPressed();
    }
}

hope it will help you... !!!

Upvotes: 0

Related Questions