github:即使重新加载浏览器也会留下评论,为什么? [英] github: comment will be remaining even if reload browser, why?
问题描述
当我用 github 的 issue page 写评论时,我注意到即使我重新加载浏览器,评论体仍然存在.
我检查了 localStorage、sessionStorage、cacheStorage、IndexedDB、cookie、但我没有找到我写的句子的实例.
另外,我检查了 Chrome Devtool 的网络选项卡,但没有发现任何可疑的网络流量.
github.com是如何实现这个恢复功能的?
他们正在使用 SessionStorage
来做到这一点:
离开页面:
- 选择所有以
.js-session-resumable
作为选择器的输入字段 - 将 {id, value} 输入对放入数组中
- 将其放入
SessionStorage
作为session-resume:/current/page/path
页面加载时:
- 检查
SessionStorage
中是否有任何带有 - 如果是,更新输入值并从
SessionStorage
中删除此记录
session-resume:/current/page/path
键的值注意:如果你在一个页面中写了一条评论(没有提交它)然后转到另一个页面,那么你可以看到你的评论保存在SessionStorage
中.p>
When I write a comment with github's issue page, I noticed that the comment body remains even if I reload the browser.
I have checked localStorage, sessionStorage, cacheStorage, IndexedDB, cookie, but I found no instance of the sentence that I wrote.
Also, I have checked the network tab of Chrome Devtool, but I could not find any suspicious network traffic.
How does github.com achieve this recovery function?
They are using SessionStorage
to do this:
On Page Leave:
- 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
On Page Load:
- 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
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屋!