如何在按下F5或刷新按钮时仅刷新页面的一部分 [英] How to refresh only a part of the page when F5 or refresh button is pressed

查看:777
本文介绍了如何在按下F5或刷新按钮时仅刷新页面的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个包含所有页面共享菜单的Web应用程序。因此,我决定使用jquery加载div中菜单按钮链接的内容。

I'm designing a web application that has a shared menu for all pages. Due to this i decided to load the contents linked by the menu buttons inside a div, using jquery.

所以,我有这个:

     $("#AddNewProductBtn").click(function() {
       $("#content").load("addproduct.html");
   });

我想跟踪#contentdiv中显示的页面。如果用户刷新页面,我想在#content中加载相同的页面。有没有办法做到这一点,还是有任何解决方法?

I want to keep track of the page displayed inside the "#content" div. If the users refreshes the page I want to load the same page in "#content". Is there any way to do this, or is there any workaround?

我看到一些网站使用iframe加载页面,但当用户点击按钮时网址也改变了。我没有找到任何关于如何做的信息。

I saw some websites that use an iframe to load the pages, but when a user clicks a button in the menu the url is also changed. I didn't find any info on how to do that.

谢谢

推荐答案

您应该将参数附加到网址的哈希部分(在#之后),例如domain.com/index.php#addproduct

You should append parameter to the hash part of the url (after #), for example domain.com/index.php#addproduct

然后在文档上。准备好检查#之后的值并加载相应的内容。

Then on document.ready check the value after # and load the corresponding content.

一些插件如 jQuery历史使用这种技术。

Some plugins like jQuery history use this technique.

此外,您可以在浏览器中利用本地存储和缓存部分代码,因此您不会在第二次使用AJAX调用加载内容。

Additionally, you can leverage the local storage and cache parts of the code at the browser, so you won't load the content with AJAX call the second time.

这篇关于如何在按下F5或刷新按钮时仅刷新页面的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆