回到上一页,不使用jquery而不是angularjs刷新 [英] Go back to previous page without refreshing using jquery, not angularjs

查看:73
本文介绍了回到上一页,不使用jquery而不是angularjs刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地运行脚本,在其中一个函数中,它会转到不同的页面。一旦它这样做,我希望它返回到上一页并继续在本地运行脚本。

I am running a script locally and in one of the functions, it goes to different page. Once it does that, I want it go to back to previous page and continue running the script locally.

有没有办法在不刷新页面的情况下返回上一页。
我使用 parent.history.back(); 这会返回到上一页但刷新页面以便我的脚本停止运行。

Is there a way to go back to previous page without refreshing the page. I used parent.history.back(); this goes back to previous page but refreshes the page so my script stops running.

推荐答案

有没有办法在不刷新页面的情况下返回上一页?



TL; DR - 简短回答是否

   没有刷新页面就无法返回。

Is there a way to go back to previous page without refreshing the page?

TL;DR - The short answer is "No"
    There is no way to go back without "refreshing" the page.

刷新是一个模糊的术语,没有确切的技术含义......

"refresh" is a somewhat vague term without an exact technical meaning ...

无论是浏览器的后退按钮还是 .history.back()告诉浏览器加载它在历史记录中保存的上一页。

Going "back" by any means, whether it's the browser's back button or your .history.back() tells the browser to load the previous page it holds in its history.

页面是从浏览器缓存加载还是从服务器重新请求的页面是浏览器,不取决于你。

Whether the page is loaded from the browser cache or re-requested from the server is up to the browser, not up to you.

在任何情况下,浏览器是否会重新解析DOM和/或重新渲染页面。实际上,它要做的事情。

In any case, it is again up to the browser whether it will re-parse the DOM and/or re-render the page. Which, in reality, it is going to do.

其中任何一个都可以称为刷新。

Any of these could be called "refresh".

然而,那时,浏览器将开始解析并执行任何存在的脚本。 继续在页面在任何情况下卸载中的脚本中的任何地方继续。

At that time, however, the browser will start parsing and executing any scripts present. It will not continue wherever it was in the scripts at the time the page unloaded under any circumstances.

浏览器返回的页面是从服务器收到的HTML文本,但脚本可能在页面加载后显着修改了DOM。这些脚本需要从一开始就重新运行,当时通过返回重新加载页面。

The page the browser goes back to is the HTML text as it was received from the server, but scripts could have significantly modified the DOM after the page was loaded. Those scripts need to run again, from the beginning, when the page is reloaded by going back.

可以想象编写一个保存DOM状态和js执行的浏览器离开页面时的状态,并在您返回时恢复该状态,但不存在此类浏览器。

It's conceivably possible to write a browser that saves the DOM state and js execution state when you leave a page, and restore that state when you return, but no such browser exists.

取决于具体内容你的实际目标就是这样,可以完成很多事情,例如 pushState() replaceState() ,单页Web应用程序, XMLHttpRequest ,使用< iframe> 等,您可以将当前页面内容(DOM)替换为其他内容,而无需实际使用转发,并在你返回页面后恢复保存的DOM,

但这对于Stackoverflow问题来说太大了。

Depending on what your actual goals are for this, there are many things that could be done such as pushState() and replaceState(), single-page web applications, XMLHttpRequest, using <iframe>, etc. where you could replace the current page content (DOM) with other content without actually going "forward", and restore the saved DOM later when you "return" to the page,
but that's far too large a topic for a Stackoverflow question.

这篇关于回到上一页,不使用jquery而不是angularjs刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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