javascript - Trigger event when user clicks the browsers back button -


is possible jquery trigger function when user clicks browsers button. have lightbox/widget when open fills window when open. there close button etc if closed if user hit button mistake.

i have far function doesnt seem run @ all

$(window).on("navigate", function (event, data) {             event.preventdefault();             console.log('back pressed');             var direction = data.state.direction;             if (direction === 'back') {                 if(widgets.full_active){                     $('.close', widgets.active_widget).click();                     event.preventdefault();                     console.log('close this');                 }             }             if (direction === 'forward') {                 // else             }         }); 

by not running line @ start of function event.preventdefault(); should mean page never changes

usually, using native javascript api browser, described here: manipulating broser history.

with jquery, see people using plugin: history.js, although have no idea it's status.

the event you're looking onpopstate.

a popstate event dispatched window every time active history entry changes between 2 history entries same document.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -