简体   繁体   English

使用Ajax“更改页面”时的后退按钮功能

[英]Backbutton functionality when “changing Pages” with Ajax

In our application, we don't have "real" links anywhere, but all the pages are loaded with ajax. 在我们的应用程序中,我们在任何地方都没有“真实”链接,但是所有页面都加载了ajax。 This would look something like this: 看起来像这样:

function changePage(module, params){
//Ajax call is done, content is being displayed in the content div
}

And so, a "link" would just be something like this: 因此,“链接”就是这样的:

<div class="link" onclick="changePage('Content_Emplyee', 123)">To Employee 123</div>

This has all been working great, the only problem is, that of course, clicking the back button will leave the page. 这一切都很好,唯一的问题是,当然,单击“后退”按钮将离开页面。 Is there any way one can override the backbutton, so it will act like the user think it would? 有什么方法可以覆盖后退按钮,因此它会像用户认为的那样起作用吗? In this case, after following the Employee link, the back button should lead back to the menu. 在这种情况下,单击“雇员”链接后,“后退”按钮应回到菜单。 After that, the forward button would go back into this Employee etc. 之后,前进按钮将返回到该Employee等。

You can use history.js , which provides the functionality you're looking for. 您可以使用history.js ,它提供了您想要的功能。 With it, you can handle browsers' history back calls to return to your previous state, without leaving the page. 有了它,您可以处理浏览器的历史记录回叫,以返回到以前的状态,而无需离开页面。

This is very useful for one-page web application, but as already pointed out, ajax links can lead to SEO limitations. 这对于一页Web应用程序非常有用,但是正如已经指出的那样,ajax链接可能会导致SEO限制。

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

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