2

So what I want is to do this:

if (top != self) {
    top.location = self.location;
}

on self.location; change event. (it is possible to use jQuery if really needed but I would love not to) Is it possible and how to do such thing?

The main idea is to keep all popup windows on top. And here we try to modify window code so that it would get onto top when user clicked on main page to open new one. So I figured we shall subscribe and listen to self.location change event. I wonder how to do it?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Rella
  • 65,003
  • 109
  • 363
  • 636

2 Answers2

6

Are you trying to do 'frame busting'? Or are you wanting to know when top.location changes? If the latter, I presume this is to detect changes to the hash tag value of the URL, otherwise a location change loads a new page, thus your JS could never run.

If you want to check hash-tag change events (that is, content that is after the # in a URL), read up on this similar question on SO: On-Window-Location-Hash-Change.

If this is about frame busting, there are a lot of good related questions on SO such as Frame Buster Buster.

As well as a interesting blog post on Coding Horror.

Community
  • 1
  • 1
Matt
  • 41,216
  • 30
  • 109
  • 147
1

Did you mean?

if (top.location != self.location) { top.location=self.location; }
Ish
  • 28,486
  • 11
  • 60
  • 77
  • yes but I need not to find it out only once. I need somehow to subscribe to change event. – Rella Dec 03 '10 at 00:54
  • Just stick the above in a setInterval – David Tang Dec 03 '10 at 01:06
  • @box9 looks like a bad ideato me - JS it willnot be as responsive as needed or willeat lotof CPU – Rella Dec 03 '10 at 01:11
  • @Kambumbus I'm not sure if there's another way - if there is go for it, but setIntervals aren't that bad for performance, and is a valid method for a number of things. Have a look at one example - livequery: http://docs.jquery.com/Plugins/livequery – David Tang Dec 03 '10 at 01:25