How to go back page when back button of android is pressed


#1

How to go back page when back button of android is pressed using javascript


#2

You can listen to the backbutton event :slight_smile:

document.addEventListener('backbutton', doSomething, false);

function doSomething(e) {
    // do something
    console.log("Back button pressed!");

    // prevent the default Android back button behavior!
    e.preventDefault();
}

#3

how i apply this to web page ??


#4

Please sort out this
how to go index.html or any other page by back button of android device … please help u r my life line now


#5

You could add this code inside your script tags on the HTML page you are on. If you don’t have a page, you can try this: https://www.kirupa.com/html5/html5_starting_template.htm

:slight_smile:


#6

please kirupa sort out my index.html problem by pressing back button of android device …please tell me the code


#7

I can’t do the work for you, since I don’t even know what the work is. The code I provided will allow you to check for the back button being pressed. If you want to next go to index.html, you can use the following:

window.location.href = "index.html";


#8

i exactly use this but how do i trigger it on back button


#9

When you click the back button on the device, the code will run. Is it not working when you try?


#10

yes it doesnot work man when i hit the back button