当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Find the real Parent Element

问题描述:

I have a website that runs out of an iframe.

To logout I run the following JavaScript with a URL and this works fine.

 window.parent.location.href

I catch I have is sometimes if I don't exit the site correctly and then reconnect I endup with 2 iframes (potentially more).

Is there a way to make the following JavaScript find the outer most (the true parent) of all potential iframes?

 window.parent.location.href

I want to make sure no matter how many iframes are present the redirection will still occur.

any advice would be great... thx

网友答案:

Use window.top instead of window.parent

网友答案:
topParent = window;

while (topParent.parent) {
    topParent = topParent.parent; 
}

// do whatever you want on topParent
分享给朋友:
您可能感兴趣的文章:
随机阅读: