Get id of div in parent document
I need to get the id of a div
in the parent document of a开发者_StackOverflown iframed document. The actual scenario is I have a facebook application developed using FBML. The canvas page contains an iframe
. If the user clicks on a button inside the iframed document, I need to display a div in the canvas page that is hidden when loading.
Thanks in advance...
did you try parent.document.getElementById('YOUR_ID');
?
Are both documents (parent and iframe) in the same domain? If no, then browser doesn't allow you to access to parent document for security reasons.
EDIT: If both documents are in the same domain then you can access the element of parent document as follows:
var parentDoc = parent.document;
var el = parentDoc.getElementById("foobar");
try $(this).parent().attr('id')
精彩评论