Javascript使用哈希值重新加载页面 [英] Javascript reload the page with hash value

查看:106
本文介绍了Javascript使用哈希值重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一些进程之后在外部javascript文件中使用此语句刷新页面。

I am trying to refresh the page with this statement in external javascript file after some processes.

window.location.href = window.location.href

它完全重新加载页面但我想滚动到特定位置后重装。
所以,我把它放在页面上。

It perfectly reload the page but I want to scroll to the specific location after reload. So, I put this on the page.

<a name="uploadImgSection"></a>

并将javascript更改为

And change the javascript to

window.location.href = window.location.href + "#mypara";

此代码不会重新加载/刷新页面

This code doesn't reload/refresh the page either

window.location.hash = "#uploadImgSection";
window.location.href = window.location.href;

当我这样做时,它根本不会重新加载页面。有什么办法可以用滚动条位置重新加载页面吗?

When I do that, it doesn't reload the page at all. Is there any way I can reload the page with scroll bar position?

推荐答案

window.location.href += "#mypara";
location.reload();

首先添加哈希值,然后重新加载页面。哈希将保留在那里,页面将被重新加载。

First add the hash, then reload the page. The hash will remain there, and the page gets reloaded.

经过测试,无效。

ps:如果网址中已存在哈希,您可能需要通过 location.hash 直接更改它 .href

ps: If a hash already exist in the URL, you may want to directly change it via location.hash instead of .href.

这篇关于Javascript使用哈希值重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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