views:

39

answers:

1

Is there any way to randomly access the URLs in Javascript's History object in Safari? I'm writing an extension where I need to, on a specifically-formatted page request, capture the URL of the previous page. From what I've been able to find, the History object definition is non-standard across browsers. Safari only seems to expose its length property and the standard methods that actually move within the history. Where other implementations expose current, previous and next properties, I can't see anything that tells me Safari does the same.

I've also tried document.referrer, but that doesn't appear to get populated in this case.

I just need to display the previously accessed URL on a given page. Is there any other way to access that URL?

Thanks.

+1  A: 

You can't really do this, at least in any white-hat way. By design. You can step the user backward and forward, but you can't see the URLs.

Less scrupulous script-writers have of course taken this as a challenge. I believe the closest they've come is to dynamically write a bunch of known comparison links to the page, and then inspect them to see if they're showing in the "visited" color state. Perhaps if you're working in a closed and predictable environment (an intranet app?), with a known set of URLs, this might be a valid approach for you. Then again, in such an environment you could deal with this on the server side with session management.

Ken Redler
As mentioned in my question, Mozilla (and others?) expose a `previous` member that would do _exactly_ what I'm after. Unfortunately, that does me no good in a Safari/WebKit environment so it appears that the answer is...you can't. I'm going to avoid crazy hacks and just forego the feature I was working on for a while.
Rob Wilkerson
Rob, you're right about `previous`, but only in the very special case where the user is running a cryptographically signed script with `UniversalBrowserRead` privileges granted -- and of course only in Mozilla...
Ken Redler