Solved

get URL from browsers history list

Posted on 1998-09-15
13
310 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.
0
Comment
Question by:georgedb
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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
0
 

Author Comment

by:georgedb
Comment Utility
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???
0
 
LVL 4

Expert Comment

by:rafistern
Comment Utility
You can refer to the window that opened you as "opener".
Thus:
 opener.history.back();
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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
0
 
LVL 4

Expert Comment

by:rafistern
Comment Utility
You are right, what I wrote will send the other page back in its history, not send the new one there.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:georgedb
Comment Utility
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

0
 

Author Comment

by:georgedb
Comment Utility
Maybe with a Java applet or whatever, as long as the clients don't need to change something.... Cheers, George
0
 
LVL 28

Expert Comment

by:sybe
Comment Utility
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.
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 120 total points
Comment Utility
George. I think we have now established that my original answer was THE answer (and I understood that you wanted to know any referrer avalable, be it yourself or another site).

Your question pops up regularly and there is only the methods of using the referer and the signed, netscape only method I gave as an answer. With MSIE 3 you won't even get a referer since it is not set in that browser.

I paste the original answer in here and hope you will accept it and when accepting it not grade it a D just because it does not make you happy.


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>

Michel
0
 

Author Comment

by:georgedb
Comment Utility
And no other tricks like loading a frameset and going back in history in one frame?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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
0
 

Author Comment

by:georgedb
Comment Utility
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
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Location of Javascript on HTML page 3 25
Asp.net mvc 5 5 15
onOpen 14 38
Uncaught TypeError: can't read property 1 13
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now