我可以使用 JavaScript 检查浏览器历史记录中是否有下一页吗?
这是一个简单的描述:我正在使用 iWebKit 将网页显示为全屏 iPhone 应用程序。当您这样做时,您获得了空间,但失去了导航按钮。我可以在页面上放置充当前进/后退的按钮并重新获得该功能。这是可取的,因为我可以将其他内容与这些按钮放在同一行(例如“主页”按钮和标题),
我希望能够控制这些由 javascript 驱动的前进和后退按钮的显示,取决于是否确实有下一页或上一页可供访问。例如,如果没有下一页,则下一页按钮可以变灰且不可点击。如果我无法控制按钮的显示方式,则它们可以单击但没有任何效果。这可能会导致用户混淆。
总之,我想知道是否有任何可以实际访问的数据可以告诉我历史记录中是否有下一页。并且,就此而言,上一页。根据我的阅读,出于安全原因,history.next
被隐藏。 history.forward()
和 history.go(1)
似乎仅用作实际转换页面的方法,而不是检查这些页面是否存在。 history.length(
) 告诉您历史记录中有多少页,但据我所知您无法确定您在该队列中的位置。
有没有办法检查浏览器历史记录中是否有下一页/上一页?
Here is a quick description: I'm using iWebKit to display a webpage as a full screen iPhone app. When you do this, you gain real estate, but you lose the navigation buttons. I can put buttons that act as forward/back on the page and recapture that capability. This is desirable, as I can put other content on the same line as those buttons (like a "home" button, and a title)
I'd like to be able to control the display of these javascript-powered forward and back buttons, depending on whether there actually is a next or previous page to go to. For example, if there is no next page, the next button can be grayed out and is not clickable. If I cannot control how the buttons are displayed, they are clickable but have no effect. This may lead to user-confusion.
In conclusion, I want to know if there is any data that can actually be accessed that will tell me whether there is a next page in the history. And, for that matter, a previous page. From my reading, history.next
is hidden for security reasons. history.forward()
and history.go(1)
seem to be only useful as ways to actually transition pages, not check to see if those pages exist. history.length(
) tells you how many pages are in the history, but AFAIK you can't figure where you are in that queue.
Is there any way to check whether there is a next/previous page in browser history?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
什么巨大的安全问题?浏览器已经使用您的引荐来源网址对服务器进行 ping 操作,众所周知,您永远不能在地址中包含敏感信息(例如在 $_GET 中传递密码),仅就这个问题而言。
我知道您可以访问上一页,我确实知道这一点。
What huge security issue?! The browser already pings the server with your referrer, it's a well known fact that you can NEVER include sensitive information in the address (such as passing passwords in the $_GET), for this issue alone.
I know you can access the previous page, I know that for a fact.
奇怪的是,虽然我知道如果可以查看浏览器历史记录将会出现巨大安全问题,但我(轻松)设法列出了 Firefox 4b9 中的当前历史记录:
通过此列表,您可以可以检查最后一个和/或第一个项目是否与
window.location.href
相对应(所有属性history.current
均受保护:=S)。如果它与其中之一相对应,则您可能位于列表的开头或结尾(但您也可能位于列表中间某处的同一地址);如果没有,你绝对不在历史的边缘。现在是坏消息:由于您想将其应用于基于 WebKit 的浏览器,我在 Chromium 中测试了上述代码,但是
window.history
不在那儿。Oddly enough, though I understand there would be a huge security issue if it is possible to look at the browser history, I (easily) managed to list the current history in Firefox 4b9:
With this list, you can check whether or not the last and/or first item correspond with
window.location.href
(of all propertieshistory.current
is protected :=S). If it corresponds with one of them, you might be at the beginning or end of the list (but you might as well be at the same address somewhere in the middle of the list); if not, you're definitely not at the edges of history.And now the bad news: as you want to apply this to a WebKit-based browser, I tested the above code in Chromium, but the array-like items of
window.history
were not there.