如果 Javascript 被禁用,什么是非侵入式历史后退按钮或替代方案?
如果 JavaScript 被禁用,有什么方法可以链接到会话历史记录中的上一个文档?
PHP 可以用来简单地链接到 REFERRER 还是有更好的选择?
编辑:除此之外,之前的帖子变量可以保留吗?
If JavaScript is disabled what's a way of linking to the previous document in the session history?
Can PHP be used to simply link to the REFERRER or is there a better alternative?
Edit: Further to this, can previous post variables be retained?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实将客户端会话历史记录中先前文档的想法与服务器会话历史记录混合在一起。
由于 Javascript 是客户端,因此执行 History.back() 会将控件呈现给浏览器,然后浏览器决定历史记录中的最后一个页面(请记住,最后一个页面可能不是您域中的页面)。当您使用服务器端 PHP 时,HTTP 标头引用者就是浏览器提供给您的任何内容。如果您的服务器端 URI 因显式单击链接、表单 GET/POST 等而未被调用,则您的脚本可能不会获得引用标头值。
如果您只想捕获站点域内的引荐来源网址,则可以开始在服务器端(在用户会话中)维护面包屑路径。例如: $_SESSION['breadcrumbs'] = array( 'page1', 'page2', ... )
POST 变量也可以保留在 SESSION 中,尽管我从未见过这样做的充分理由。如果您尝试返回表单的错误消息并希望返回 POST,则不应保存原始 POST 的状态。
You're really mixing the idea of previous document in client session history vs. server session history.
Since Javascript is client-side, executing a history.back() renders the control to the browser, which then decides which page was last in the history (keeping in mind that the last page may not be a page within your domain). When you're using server-side PHP, the HTTP header referrer is whatever the browser supplied to you. If your server-side URI wasn't called as a result of an explicit click on a link, form GET/POST, etc. , your script probably won't get a referrer header value.
If you only want to capture the referrer within your site's domain, you can start maintaining a breadcrumb trail server-side (in the user's session). eg: $_SESSION['breadcrumbs'] = array( 'page1', 'page2', ... )
POST variables can be persisted in the SESSION too though I've never seen a good reason to do so. If you're trying to return an error message for a form and expect to get back the POST, you shouldn't be saving the state of the original POST.