Android backbutton not working framework7 v3


#1

Plz help this Issue

I write below code my app.js but not work properly

document.addEventListener("backbutton", onBackKeyDown, false);

function onBackKeyDown() {
    // Handle the back button
}

#2

And what you expect this code to do? From what i see it doesn’t do anything


#3
"use strict"; 
// Dom7
var $$ = Dom7;

// Init App
var app = new Framework7({
  root: '#app',
  theme: 'md',
  routes: routes,
  view : {
	pushState: false
  }
});

var opened = 0;
function exitApp(){
	if (opened > 0) {
		return false;
	} else {
		myApp.confirm('Are you sure you want to exit?', 'Exit App', 
		  function () {
			navigator.app.exitApp();
		  },
		  function () {
			opened = 0;  
			return false;
		  }
		);
		opened = 1;
	}
}

document.addEventListener("backbutton", onBackKeyDown, false);
		
function onBackKeyDown() {
	// Handle the back button
	if(mainView.activePage.name == 'index'){
		exitApp();
		e.preventDefault();
	} else {
		myApp.closeModal()
		mainView.router.back();
		return false;
	}
}

#4

You probably will see errors in console. But for example, i can’t see reference to what is mainView and myApp you are referring in back button handler


#5

mainView.activePage.name ? (This is for v1)

mainView.router.currentPageEl - HTMLElement of current page


#6

Thank u… but i dont understand this issue…
Plz… if possible you write the correct code


#7

something like this

"use strict"; 
// Dom7
var $$ = Dom7;

// Init App
var app = new Framework7({
  root: '#app',
  theme: 'md',
  routes: routes,
  view : {
	  pushState: false
  }
});

var opened = 0;
function exitApp(){
	if (opened > 0) {
		return false;
	} else {
		app.dialog.confirm('Are you sure you want to exit?', 'Exit App', 
		  function () {
			navigator.app.exitApp();
		  },
		  function () {
			opened = 0;  
			return false;
		  }
		);
		opened = 1;
	}
}

		
function onBackKeyDown() {
	// Handle the back button
	if(app.views.main.history.length == 1){
		exitApp();
		e.preventDefault();
	} else {
		app.dialog.close();
		app.views.main.router.back();
		return false;
	}
}

document.addEventListener("backbutton", onBackKeyDown, false);