Jono
Jono

Reputation: 18108

html5/jquery back button

Is there a library or piece of code that makes a specific button act as like a proper browser back button where it will take you to the previous page that was loaded before?

At the moment I'm just specifying the href of what I assume was the page that was previously loaded but came to the conclusion that this won't work because a screen could have been accessed from different screens.

Is there an example of this or do I need to create my own logic that tracks page history some how?

Thanks

Upvotes: 1

Views: 5786

Answers (2)

Omar
Omar

Reputation: 31732

Navigate back - Single-file template:

$('.selector').on('click', function (e) {
  e.preventDefault();
  var page = $.mobile.activePage.prev('[data-role=page]');
  $.mobile.changePage(page, {
    transition: 'flip',
    reverse: true
  });
});

Navigate back - Multi-files template:

$('.selector').on('click', function (e) {
  e.preventDefault();
  var page = document.referrer;
  $.mobile.changePage(page, {
    transition: 'flip',
    reverse: true
  });
});

Demo

Upvotes: 2

Christopher Thrower
Christopher Thrower

Reputation: 730

You can use the JavaScript back method;

function backButton() {
    window.history.back()
}

<a onclick="backButton()">Go back</a>

Or a different method;

<a onclick="history.go(-1);">Go back</a>

Upvotes: 6

Related Questions