如果人从另一个选项卡中刷新页面 /访问,请删除编辑数据的能力?
imgur 具有一个有趣的功能,
- 您可以在其中使用 https://imgur.com/upload
- 上传完成后,您将被重定向到帖子的页面,在那里您可以根据需要编辑标题。如果您在另一个选项卡中刷新页面 /访问它 - 编辑标题的能力已经消失。
Imgur如何做到这一点? 我的猜测是饼干有点涉及,但我不确定。
imgur has an interesting feature where
- you can create a post using https://imgur.com/upload
- after the upload finishes, you will be redirected to the post's page where you can edit the title as much as you want. If you refresh the page / visit it in another tab--the ability to edit the title is gone.
How is Imgur doing this?
My guess is cookies are involved somehow, but I'm not sure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不想使用cookie或会话,而不是一种方法来实现这一目标。创建发布/上传到true(最初为false)时更新状态。当用户刷新页面时,该状态将自动为false,因为该组件刚刚呈现。
注意: - 如果您不想使用状态,则可以使用Redux来实现此解决方案。
之后,使用该状态或REDUX状态以启用/禁用编辑帖子的能力。
If you do not want to use cookies or session than one way to achieve this is by using useState. update the state when post is created/upload to true(initially false). When user will refresh the page then that state will automatically be false because the component is rendered just now.
Note:- If you do not want to use state you can use redux also to achieve this solution.
After that use that state or redux state to to enable/disable the ability to edit the post.
$ _ $ _ session
要实现此目的/docs/hooks-state.html“ rel =“ nofollow noreferrer”> usestate 在创建create保存可编辑资源的ID上
您可以伪造重定向,这意味着显示编辑页面并将视图页面放入URL
重定向时,设置cookie: https://remix.run/docs/en/v1/api/remix#redirect
然后,使用 cookie api 检查该饼干。
$_SESSION
to achieve thisOn Create save the id of the editable resource, on Render if it matches enable edit and reset the saved editable id.
You can fake the redirect, which means showing the edit page and putting the view page into the URL
on redirecting, set a cookie: https://remix.run/docs/en/v1/api/remix#redirect
Then, use the Cookie API to check that cookie.
您可以检查导航类型。请参阅 @ @ @зleshref =“ https://stackoverflow.com/a/53307588/14250290”> href = on @
极寻找
重新加载
和back_forward
您可能想在后端发生某些事情,以防止恶意用户。另一个选择是在进行帖子时从后端发送令牌,并为了编辑帖子,需要将确切的令牌发送回去。只是不要将令牌保存在持续存在的任何东西中,并在刷新或新选项卡中保存。
you can check for the navigation type. see the answer from @Илья Зеленько on https://stackoverflow.com/a/53307588/14250290
the types you're looking for are
reload
andback_forward
you probably want to have something happen in the backend happen as well to prevent a malicious user.Another option would be to send a token from the backend when a post is made and in order to edit a post that exact token would need to be sent back. Just don't save the token in anything that persists and on a refresh or new tab it'll be yeeted.