简体   繁体   English

转到上一页并刷新 - 使用javascript / Jquery在一个按钮中

[英]Go To Previous Page and Refresh - both in one button using javascript/Jquery

is there any way to create a button which will on click take you to previous page and then refresh the page immediately? 有没有办法创建一个按钮,点击后会转到上一页,然后立即刷新页面? I use the following code to go back to previous page but it does not reload/refresh.. 我使用以下代码返回上一页但它没有重新加载/刷新..

<input type="button" value="Back" onClick="javascript: history.go(-1)">

Thanks :) 谢谢 :)

The only way to refresh the loaded page would be to use window.location.reload() in the new page. 刷新加载页面的唯一方法是在新页面中使用window.location.reload()

You could try getting the last URL using document.referrer (or by keeping a history of their page views in a cookie) and then adding something to the hash to make it like: 您可以尝试使用document.referrer获取最后一个URL(或者将其页面视图的历史记录保存在cookie中),然后在哈希中添加一些内容,使其像:

http://stackoverflow.com#didGoBack HTTP://stackoverflow.com#didGoBack

Then, in javascript, check to see if that hash exists using window.location.hash and if so, reload the page. 然后,在javascript中,使用window.location.hash检查是否存在该哈希,如果是,则重新加载页面。 Note. 注意。 the referrer won't be set unless they arrived at that page via a link. 除非他们通过链接到达该页面,否则不会设置推荐人。

I think I invented a way of doing this. 我想我发明了这样做的方法。 By adding a random parameter to url, we force browser to refresh... 通过向url添加随机参数,我们强制浏览器刷新...

var backLocation = document.referrer;
if (backLocation) {
    if (backLocation.indexOf("?") > -1) {
        backLocation += "&randomParam=" + new Date().getTime();
    } else {
        backLocation += "?randomParam=" + new Date().getTime();
    }
    window.location.assign(backLocation);
}

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

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