fernandofleury
fernandofleury

Reputation: 125

is there anyway to fully prevent popstate?

Im working with jquery mobile right now. And when the user clicks on the box, it will show an additional one. But when the user forced return on browser (or the backbutton), on that moment, the second box should hide, instead of going back the the prev page.

I've managed to achiev almost what I wanted with the popstate:

window.onpopstate = function(event) {
  if($('div').is(':visible') {
     closeFunction();
     event.stopImmediatePropagation();
  }
}

But it still changes the URL.

For example, if i has a nav like this:

index > home > internal(with box)

And then i pressed the back button

index > home

Will still trigger the url change, but not the page change.

I've tried with pagebeforechange, but with the same result.

Any ideas?

Upvotes: 2

Views: 1622

Answers (1)

hckrmoon
hckrmoon

Reputation: 21

the popstate event is not cancellable. referred doc

Specification: HTML5
Interface: PopStateEvent
Bubbles: Yes
Cancelable: No
Target: defaultView
Default Action: None

Upvotes: 2

Related Questions