开发者

Detect if the url in an iFrame has changed

Is there anywa开发者_运维知识库y to detect if a user clicks a link inside of an iframe if the iframe is not on the same domain as the parent page?

EDIT: I don't have access to the iframed page. I only own the parent window.


No. Due to the javascript same-origin policy, you cannot access any members of the iframe's DOM if the iframe did not serve from the same domain as the page on which your javascript is running.


if (window.domain !== top.domain) {
  // they are not the same
}


Try this.

var isInSameDomain = (window.location.host == window.parent.location.host);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜