github:即使重新加载浏览器,评论也将保留,为什么? [英] github: comment will be remaining even if reload browser, why?
问题描述
当我在github的问题页面上写评论时,我注意到即使重新加载浏览器,评论正文仍然存在.
When I write a comment with github's issue page, I noticed that the comment body remains even if I reload the browser.
我已经检查了localStorage,sessionStorage,cacheStorage,IndexedDB,Cookie, 但是我找不到我写的句子的实例.
I have checked localStorage, sessionStorage, cacheStorage, IndexedDB, cookie, but I found no instance of the sentence that I wrote.
我还检查了Chrome Devtool的网络"标签,但找不到任何可疑的网络流量.
Also, I have checked the network tab of Chrome Devtool, but I could not find any suspicious network traffic.
github.com如何实现此恢复功能?
How does github.com achieve this recovery function?
推荐答案
他们正在使用SessionStorage
来做到这一点:
They are using SessionStorage
to do this:
页面离开:
- 使用
.js-session-resumable
作为选择器选择所有输入字段 - 将{id,value}对输入放入数组
- 将其作为
session-resume:/current/page/path
放入SessionStorage
- select all of the input fields with
.js-session-resumable
as selector - put {id, value} pair of inputs in an array
- put it in
SessionStorage
assession-resume:/current/page/path
页面加载:
- 通过
SessionStorage
中的 - 如果是,请更新输入值并从
SessionStorage
中删除此记录
session-resume:/current/page/path
键检查是否有任何值
- check if there are any values with
session-resume:/current/page/path
key inSessionStorage
- if yes, update values of inputs and remove this record from
SessionStorage
注意::如果您在页面中写评论(不提交)并转到另一页面,那么您可以看到您的评论保存在SessionStorage
中.
Note: If you write a comment in a page (without submitting it) and go to another page, then you can see your comment saved in SessionStorage
.
这篇关于github:即使重新加载浏览器,评论也将保留,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!