简体   繁体   English

在浏览器中重新加载带有注入的javascript的页面

[英]Reloading page with injected javascript in Browser

So I created a JS script that does something on a page from the browserconsole, but when it is ready, the page needs to be reloaded in order to work properly afterwards, but if I reload the page, the JS will be deleted, because it is only injected by the browsers console. 因此,我创建了一个JS脚本,该脚本可通过浏览器控制台在页面上执行某些操作,但是准备就绪后,需要重新加载页面才能正常工作,但是如果我重新加载页面,则JS将被删除,因为它仅由浏览器控制台注入。

How do I reload the page, but with my JS-Code already injected, or how do I reload the page, so that the injected JS will not be deleted? 如何重新加载页面,但是已经注入了我的JS代码,或者如何重新加载页面,以便不会删除注入的JS?

Thanks Hiro 谢谢Hiro

If you want to save some variables then you should use local or session Storage to save a variable. 如果要保存一些变量,则应使用本地或会话存储来保存变量。

localStorage.setItem("lastname", "Smith");  

and after refresh you can get it with 刷新后,您可以使用它

alert(localStorage.lastname); // Smith  

If you want something more complex you should use Ajax and PHP. 如果您想要更复杂的东西,则应该使用Ajax和PHP。

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

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