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>

And change the javascript to

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

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

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

当我这样做时,它根本不会重新加载页面.有没有办法用滚动条位置重新加载页面?

推荐答案

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:如果URL中已经存在哈希,您可能希望通过location.hash而不是.href直接更改它.

Jquery相关问答推荐

jQuery从JSON创建嵌套列表

如何使用 jQuery 的 drop 事件上传从桌面拖动的文件?

更改高亮 colored颜色

jQuery 1.4.1 中缺少 JSON 字符串化?

为什么 jQuery 不使用 requestAnimationFrame?

jQuery / Ajax - $.ajax() 将参数传递给回调 - 使用好的模式?

使用 jQuery 为 box-shadow 设置动画的正确方法

如何使用 jQuery 的 getJSON() 方法传递请求标头?

使用 jQuery 的并行异步 Ajax 请求

如何判断输入日期是否等于今天的日期?

数据表警告(表 id = 'example'):无法重新初始化数据表

如何在单击时 Select 多选 Select 框的所有选项?

对混合的字母/数字数组进行排序

jQuery/JavaScript 碰撞检测

有没有办法放大 D3 力布局图?

使用 JQuery 更改 :before css Select 器的宽度属性

复选框值始终为打开

使用 jQuery DataTables 时禁用第一列的自动排序

如何获得元素的正确偏移量? - jQuery

CSS3 相当于 jQuery slideUp 和 slideDown?