Can I check if there is a next page in browser history w/Javascript?
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 开发者_如何学Gois 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?
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:
var i, h = window.history, o = document.getElementById("output");
o.innerHTML = "<b>" + window.location.href + "<\/b><br>";
for (i = 0; i < h.length; i++)
o.innerHTML += h[i] + "<br>";
With this list, you can check whether or not the last and/or first item correspond with window.location.href
(of all properties history.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.
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.
精彩评论