Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have seen some elegant solutions on fetching the parents document from iframe - like e.g. this one. However, I can't make it work - and I didn't think this was possible due to securities issues (cross domain scripting?)?

My question is; can I still access the parents document from inside an iframe - or has this changed the recent years? If I should be able to access this; any thoughts on why I get undefined when printing parent.document or window.parent.document from the content of the iframe?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
131 views
Welcome To Ask or Share your Answers For Others

1 Answer

It's still possible to access the parent from within a frame provided that the domains match.

For example, have a look at these fiddles:

You can access the parent through:

window.parent
parent
top          //If the parent is the top-level document
window.top

The variables parent and top can be overwritten (usually not intended). It's safer to use window.parent to be more safe. Alternatively, you can replace window by document.defaultView.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...