last day (15 days later) » 

5:57 PM
0
A: Select iframe parent of an element in iframe, doing outside the iframe

the_warrierif you use javascript you could use this (assuming you used onclick or addeventlistener: function something(clicked) { var ifrparent = clicked.parentNode.parentNode; } EDIT: if the p tag is in the src of the iframe, then in your onclick function, you would use var ifrparent = window.frame...

 
It gives null....
 
OH wait is the p in the document that is the source of the iframe?
^if so, then check my edit
 
not very sure what you mean, but the p is loaded from another html source, and that page is loaded as an iframe in the main page.
 
yes so then use what i said in the edit
 
window.frameElement gives null again.... Because I'm running the js in the main page, so window will always pick the main page.
 
6:01 PM
hey i think its better if we talk over chat rather than spamming your comments
so is there a reason that you want to come from inside the source?
 
 
1 hour later…
7:12 PM
Well, not exactly true :D Actually I ended my real problem with the #document node. My Chrome extension is designed to listen to tons of buttons inside an iframe, then makes use of the user selection. Say I got the #document and saved it as temp. Then temp.getSelection() gives the wanted selection range. Here, window.getSelection() doesn't work, as nothing has been selected in the main page.
Also, the main page has several iframe elements. And they are dynamically loaded so I can't get its id in advance. And I want my extension handle different cases so the id will change. I just want to capture the iframe which contains the button, which has been clicked by user.
Again, #document node does the work. But in this SF question, what I'm asking is that is there any way to 'jump' from inside the iframe to outside, namely the main page? It might be useful in situations like, <div id="section1"><iframe src="html1"/></div><div id="section2"><iframe src="html2"/></div> when user clicks a button in html1, I want to do something to div#section1. The buttons in html1 and html2 make no difference, it's hard to get the container with the button themselves.
 
8:11 PM
all i can think of is when i had buttons inside the iframe that i wanted to do an action on the main page, i put the javascript in an external file and called a function using the onclick method. since the onclick stemmed from the button on the source page, the window object returns the window of the source page, so i could do window.frameElement. in your case, i cant think of a way to do what youre trying to do haha sorry
wait, actually
this exactly applies to you
so if somewhere inside of html1 you have a <button blah blah onclick="something()"></button>
and up top you have <script type="text/javascript" src="something.js"></script>
then in function something()
you can call window.frameElement to get the iframe
but if your js HAS to be on the main page, i have no idea what you can do
 

  last day (15 days later) »