最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - html5jquery back button - Stack Overflow

programmeradmin0浏览0评论

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

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

Share Improve this question edited Jul 9, 2013 at 9:33 zzlalani 24.4k16 gold badges47 silver badges73 bronze badges asked Jul 9, 2013 at 9:23 JonoJono 18.1k50 gold badges141 silver badges222 bronze badges 3
  • are you using single-file or multi-files template? – Omar Commented Jul 9, 2013 at 9:49
  • single file atm but will move my JS in a JS file later – Jono Commented Jul 9, 2013 at 10:04
  • use $.mobile.changePage() in jQM as mentioned in my answer. check this demo jsfiddle/Palestinian/YMTzU – Omar Commented Jul 9, 2013 at 14:13
Add a ment  | 

2 Answers 2

Reset to default 6

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>

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

发布评论

评论列表(0)

  1. 暂无评论