We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

get URL from browsers history list

georgedb
georgedb asked
on
Medium Priority
337 Views
Last Modified: 2008-02-01
I tried several tricks to solve the following. I want to know what page the user was before he went to my page. This doesn't necessarily be because he clicked on a link, a self-types URL in the location bar, or a bookmark is possible to. If the latter two are the case, than "document.referrer" is empty. The only possible commands on the historylist are ".go()", ".back()", ".forward()"; the array is not accesible.

I tried to do "history.back()" from within a frame - fail.
I tried to open a new window and refer from there to the former window, but you can't use "self" or "parent"; you don't know that windowname.... Besides it's possible that a user uses more than 1 window at a time....

I think this problem can not be solved.
Comment
Watch Question

Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
The History array is empty if loaded form location or from 'open in new window'
so history.length will be 0 in that case - that is the only property you are allowed to look at.

The only way to acess the contents of the History array is with a signed script in Netscape:

<SCRIPT>
function showUrl() {
       netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
       alert(history[history.length-1]);
       netscape.security.PrivilegeManager.disablePrivilege("UniversalBrowserRead");
}
</SCRIPT>

This is not easily solvable

Author

Commented:
I think your answer is good, but I'm looking for a more generic solution. This might work in Netscape, though I get a "security" message and don't see were to change this setting, but I'm looking for something that can be supported by Netscape 3.0 and above and Internet Explorer 3.0 and above. Isn't there another way? Preferrably with JavaScript, but maybe something else???
You can refer to the window that opened you as "opener".
Thus:
 opener.history.back();
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
rafistern: He wants to know from where he came, not load the previous page

George, I am sorry that you rejected my answer since it is the only answer using client side detection.

If all links and bookmarks to your page was server side programs (cgi or servlets)
you could get the referer from Netscape 2+ and MSIE 4+

There is no other means than referer and my suggestion.

Michel
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
PS: The netscape security warning will only go away if the script is signed (as I mentioned)

More info here:
http://developer.netscape.com/library/documentation/signedobj/signtool/index.htm
You are right, what I wrote will send the other page back in its history, not send the new one there.

Author

Commented:
Sorry to reject your answer, but this is still not the answer to my question. Let me simplify it.... I want to know the URL (and possibly the title - things that are stored in the history array) the user came from. If he came to my site with a link, I simply would use "document.referrer". But if he came there by clicking a bookmark in his list, or clicking his home button "document.referrer" is empty. The only possible methods are
history.go(X) (where X equals a URL or an +/- integer)
history.back()
history.forward()

When you use the "opener" thing, than the windows was opened from that page the user was, and the idea I had was opening the window myself and try to find out what other open windows there were to pick the location. As I'm opening the windows myself, "opener" does not work.

I also tried to load a frame when you enter my site and jump in one of the frames back to one page back in history. I can't get that to work. I fI could, I could easily pick that URL.

Maybe the above explanation is a bit complicated.... What I "just" want is find out what the URL was the user was before he went to my site. With a normal link, no problem. With a typed in URL or with a bookmarked page, I need some trick. Or something dirty to enter that protected history list. And that's not it, it needs to work for IE 3+ and NS3+....

Sorry again to reject your answer, but it didn't really help me.... I really hope you can find something that solves my problem.

Kind regards,


George

Author

Commented:
Maybe with a Java applet or whatever, as long as the clients don't need to change something.... Cheers, George

Commented:
The history is "secured".
Netscape & Microsoft realized that some people might want to do exactly what you want. And they realized that people do not want other people to know which urls they have visited. In some cases url's (querystrings) contain sensitive/personal information.

So what they did is make the history array unreadable. Except when the user explicitely agrees (as in mplungjan's answer).

Anyway, your problem is clear, and I hope it is clear that what you want is deliberately made impossible for security reasons. If there would be a way to do what you want, then it would be a security bug.

There's no one to help you, sorry.
IT Expert
CERTIFIED EXPERT
Top Expert 2009
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
And no other tricks like loading a frameset and going back in history in one frame?
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
Thanks.
No, sorry. That would unload the frameset.

Your best bet is to keep track of what is loaded yourself in the main frameset definition page and have each page check if it is loaded in a frame - if not use the location.search to load the frameset AND the page.

If the browser is Netscape and there is no referer and no opener you can be reasonably sure your page is loaded from bookmark or location bar

With MSIE 3 most bets are off.

Just to make sure I don't have some other solution, please let me know what exactly it is you are trying to accomplish - I have scripts that can reload a page inside a frameset if bookmarked outside it and many more.

Michel

Author

Commented:
Dear Michel,

I'm not sure, but the only direct way to contact you seems by continuing this thread. I'm willing to give you all my 18 points, I hope that's sufficient ;-) If not, let me know. Only some simple questions....

You wrote:
>The only way to acess the contents of the History array is with a signed script in >Netscape:
>
>    <SCRIPT>
>    function showUrl() {
>       netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
>       alert(history[history.length-1]);
>       netscape.security.PrivilegeManager.disablePrivilege("UniversalBrowserRead");
>    }
>    </SCRIPT>
I don't know completely how this works, but it seems to work a bit like the certificate I needed to use to run HTTPS.... I'll figure it out, though I don't think I'll use it.... Another thing is that it seems that things get lots easier when you run HTTPS, you don't need to sign the script than, is that through? Does it mean than that users don't have to agree on some special certificate for a signed script than????


Another thing you wrote is:

>Your best bet is to keep track of what is loaded yourself in the main frameset definition >page and have each page check if it is loaded in a frame - if not use the location.search >to load the frameset AND the page.
[.....]
>Just to make sure I don't have some other solution, please let me know what exactly it is >you are trying to accomplish - I have scripts that can reload a page inside a frameset if >bookmarked outside it and many more.
All I would like to know is the URL where the user was when he decided to come to my page (by link, by HOME button, by bookmark or by typed in URL).....

Do you mean that you have a script that does the following?

A user is on some page X, goes to my page where I load a frame AROUND that page X so the result is a frame with two parts: the old page the user was (X) and the other part, my page. I guess IF that's possible, than it's still not possible to track the URL the user was.... The restrictions are still the same: I need to use it from NS 3+ and IE 3+ and users may get to my page not only by a referring link but also by typing in my URL, by means of a bookmark or by means of the URL that's behind their HOME button.

Cheers,


George
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.