简体   繁体   English

从JQuery Mobile历史记录中删除页面,以便“返回”按钮绕过它

[英]Remove page from JQuery Mobile history such that 'Back' button bypasses it

I've looked through the jQuery Mobile documentation to no avail, so hopefully someone here has solved what I so far haven't found a way to. 我没有看过jQuery Mobile文档,所以希望这里有人解决了我到目前为止找不到的方法。

I have a jquery mobile page, served in the usual way (call it 'item display'). 我有一个以常规方式投放的jQuery移动页(称为“项目显示”)。 It contains info about a particular item. 它包含有关特定项目的信息。 There is a button on this page that takes the user to a page in which he/she can take notes (essentially a big textarea) on the item displayed. 此页面上有一个按钮,可将用户带到一个页面,在该页面上他/她可以在显示的项目上做笔记(基本上是大文本区域)。 Clicking 'save' on the notes page POSTs and redirects back to the item display page. 单击注释页面上的“保存”,开机自检并重定向回项目显示页面。

My issue is that once the notes have been saved, I would like the 'Back' button on the item display page to link back to the page the user was at before first visiting the item display page, NOT the default behaviour of taking the user back to the notes page (since it was technically the last page the user was on). 我的问题是,一旦保存了便笺,我希望项目显示页面上的“返回”按钮链接回到用户在首次访问项目显示页面之前所在的页面,而不是默认的采取用户行为返回注释页面(从技术上讲,这是用户访问的最后一页)。

So, current behaviour: 因此,当前行为:

item list page -> item display page -> click 'Edit Notes on item' -> notes page -> click 'Save' -> item display page -> click 'Back' -> notes page. 项目列表页面->项目显示页面->单击“在项目上编辑注释”->注释页面->单击“保存”->项目显示页面->单击“返回”->注释页面。

I want to replace the last step with clicking 'Back' to take the user to the item list page. 我想用“返回”代替最后一步,将用户带到项目列表页面。

Any such luck? 有这样的运气吗? Thanks for any and all guidance you can provide 感谢您提供的所有指导

You can change pages without keeping them in browser history like so: 您可以更改页面而不将其保留在浏览器历史记录中,如下所示:

$.mobile.changePage('#page', {reverse: false, changeHash: false});

this is based on this answer: Jquery mobile, remove previous page 这基于此答案: jQuery mobile,删除上一页

I have been in the same issue as you and I have created an approach, the only one that worked. 我遇到了与您相同的问题,并且我创建了一种方法,这是唯一可行的方法。 If someone knows something better, it would be greatly helpful! 如果有人知道更好,那将大有帮助! So, let me explain how to solve (it is a bit complicated, but worked for me). 因此,让我解释如何解决(这有点复杂,但对我有用)。

You will need to override the back button to roll back the history by X pages in the html you want, for example: 您将需要覆盖“后退”按钮,以按所需html中的X页回滚历史记录,例如:

$(document).ready(function() {
    $('[data-rel=back]').click(function() {
        window.history.go(-4);
        return false;
    });
});

But, the 4 is actually a navigation counter variable in session. 但是,4实际上是会话中的导航计数器变量。

If you use jsf, it would be like this: 如果您使用jsf,它将像这样:

window.history.go(-#{mySessionManagedBean.navigationCounter});

Also, you need to initialize and increment this each page change. 此外,您需要初始化和递增此每次页面更改。

If you use jsf, it would be like this: 如果您使用jsf,它将像这样:

<h:commandButton ...>
    <f:setPropertyActionListener target="#{mySessionManagedBean.navigationCounter}" value="#{mySessionManagedBean.navigationCounter + 1}" />
</h:commandButton>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM