浏览器不记得位置的网页上查看
-
06-07-2019 - |
题
我已经做了一些搜索这个问题,我有两手空空。我希望有人能澄清的事情对我来说和点我在正确的方向。
问题: 我有个页面列表显示的结果之后提交一个搜索的形式。当一个用户点击的结果之一,浏览器进入一个新的网页显示出更多信息有关的结果。当用户然后点击"返回"的按钮以去组的结果,我浏览器重新载入页面,并显示页的顶部相反的结果,最后一次点击。
目标: 我想是这样的:当用户击的后按钮,浏览器应该回到以前的网页,而不是表示的网页,显示出该网页在以前的位置。
方案: 我完全失去了作为如何这样的结果可以实现的。能有什么要做javascript,或头发的浏览器,也许是与缓存。
解决方案 4
我通过使用php发送标头来修复此问题。这是我的解决方案:
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: store, cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", FALSE);
感谢大家的帮助。
其他提示
如果这是 令人难以置信 重要的是,我建议,调查如下:
- 添加
id
s到每个离任的链接 - 使用JavaScript捕捉
onClick
链接 - 当一个点击链接,将用户链接的
id
片段标识符, 然后链接出如所期望的
当用户击中背部按钮,它们就会返回到具体的链接,例如 http://www.example.com/#link27
而不是的 http://www.example.com/
你可能能够得到的一些想法从这里:
您可以使用javascript和jquery来设置窗口和cookie的滚动位置,以存储要滚动到的位置。在包含搜索结果的页面的javascript中,您可以使用以下内容:
var COOKIE_NAME = "scrollPosition";
$(document).ready( function() {
// Check to see if the user already has the cookie set to scroll
var scrollPosition = getCookie(COOKIE_NAME);
if (scrollPosition.length > 0) {
// Scroll to the position of the last link clicked
window.scrollTo(0, parseInt(scrollPosition, 10));
}
// Attach an overriding click event for each link that has a class named "resultLink" so the
// saveScrollPosition function can be called before the user is redirected.
$("a.resultLink").each( function() {
$(this).click( function() {
saveScrollPosition($(this));
});
});
});
// Get the offset (height from top of page) of the link element
// and save it in a cookie.
function saveScrollPosition(link) {
var linkTop = link.offset().top;
setCookie(COOKIE_NAME, linkTop, 1);
}
// Boring cookie helper function
function getCookie(name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(name + "=");
if (c_start != -1) {
c_start = c_start + name.length + 1;
c_end = document.cookie.indexOf(";", c_start);
if (c_end ==- 1) c_end = document.cookie.length;
return unescape(document.cookie.substring(c_start, c_end));
}
}
return "";
}
// Another boring cookie helper function
function setCookie(name, value, expiredays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie = name + "=" + escape(value) +
((expiredays==null) ? "" : ";expires=" + exdate.toGMTString());
}
这假设您的搜索结果链接包含 class =" resultLink"
。
答案的第一部分是你使用锚点降落在除顶部之外的某个页面上。所以,如果我在页面底部的html中有这个:
<a name="f"></a>
然后我可以通过将锚点附加到他的URL:
的末尾让用户登陆http://www.bullionvalues.com/glossary.aspx#f
因此,如果您正在谈论ASP.Net,您可以将锚点放在页面信息页面上的隐藏字段中,然后使用:Page.PreviousPage属性从搜索页面中读取它。
protected void Page_Load(object sender, EventArgs e)
{
if (Page.PreviousPage != null)
{
Object o = PreviousPage.FindControl("hfAnchor");
if (o != null)
{
HiddenField hf = o as HiddenField;
Response.Redirect(Request.Url+"#"+hf.Value);
}
}
}
不隶属于 StackOverflow