1

There is window.history object in javascript.

It's possible to get lenght of the history using window.history.lenght or redirect to the previous / next url in the history using history.go(N)

Is there any trick to get URL of the history objects? As i see it's not possible with history object, because urls are even not readonly.

Do you have any ideas?

Zelid
  • 6,905
  • 11
  • 52
  • 76
  • 4
    The first question is why you need such a thing. – rahul Aug 05 '09 at 12:17
  • For site stats. I use banner network and if someone comes from img.doubleclick.com i want to see what was the real url of the site that bring me current visitor. – Zelid Aug 05 '09 at 12:45
  • 4
    This question appears to be off-topic because it is about a support request with the doubleclick banner network. – hakre Sep 29 '13 at 08:17

2 Answers2

11

This is not possible, nor will it ever be, in any major browser. It would be a severe privacy and same origin policy violation.

chaos
  • 122,029
  • 33
  • 303
  • 309
  • 1
    At least reading the (current session) history within the current Same-Origin-Policy scope would be nice ;-) – NicBright Oct 03 '14 at 10:07
4

The browser history can be determined within javascript by detecting the color of the link. This can only work by trying different url's and we cannot get every history object.

<script>
function urlvis(url){
document.getElementById('gurl').innerHTML="<a id=geturl href="+url+" >^</a>";
x=document.getElementById('geturl');
color=document.defaultView.getComputedStyle(x,null).getPropertyValue('color');
if (color=="rgb(85, 26, 139)") visited=true; else visited=false;
document.getElementById('gurl').innerHTML="";
return visited;}
</script>
<div id=gurl></div>

Now make a hidden element in your page that can be controlled by innerHTML. NOTE That this method has only been tested to work with firefox.

EDIT:

While this was a working method once, most newer browsers will not allow you to get an accurate reading of a link's computed style. I have noticed this change starting in Firefox 4. It's about time anyways, it was a privacy concern.

Adam Fowler
  • 1,750
  • 1
  • 17
  • 18
  • This is what hackers use for cross-site – Zelid Aug 16 '11 at 11:57
  • 2
    I have tested this in Firefox 6. It doesn't work. All URLs will be the same color in FF6. The Above Example does work on FF3.6 and FF4.0. – Adam Fowler Sep 26 '11 at 01:42
  • 2
    Yes, this is from the past. There was an exploit via CSS link colors (visited links; :visited) that browser vendors had overseen and didn't address. This *should* be fixed now, however keep in mind that using the internet is not good for your privacy and computer security. An easy way to protect against such attacks (and spying websites) is to disable javascript which again has been made complicated with Firefox due to requirements by industry and advertisement partners. – hakre Sep 29 '13 at 08:57