简体   繁体   English

如何获取 self.location 更改的事件?

[英]How to get event of self.location change?

So what I want is to do this:所以我想要的是这样做:

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

on self.location ;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? (如果真的需要,可以使用 jQuery,但我不想这样做)是否有可能以及如何做这样的事情?

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.所以我想我们应该订阅并收听self.location更改事件。 I wonder how to do it?我想知道怎么做?

Are you trying to do 'frame busting'?您是否正在尝试“破坏框架”? Or are you wanting to know when top.location changes?或者您想知道 top.location 何时发生变化? 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.如果是后者,我认为这是为了检测 URL 的哈希标记值的更改,否则位置更改会加载一个新页面,因此您的 JS 将永远无法运行。

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 .如果您想检查井号标签更改事件(即 URL 中 # 之后的内容),请阅读关于 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 .如果这是关于帧破坏,那么在 SO 上有很多很好的相关问题,例如Frame Buster Buster

As well as a interesting blog post on Coding Horror .还有一篇关于Coding Horror的有趣博文。

你的意思?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM