Forum Moderators: open
It would have the effect of this:
<iframe id="myiframe" name="myiframe" onClick="myfunction()" style="width:100%;height:100%;"></iframe>
This does not seem to work... would there be another way to go about doing something with the same effect.
I have a function which changes the contents of the iframe... and I want this to be called when the iframe is clicked on.
It gets a bit complicated because there are two VERY different objects involved in thinking about this. First there is the iframe element itself - which is an object of its parent page, Then there is the window that is generated by the iframe and the document that is loaded in that window.
When you use an event handler like onclick for the iframe element, you are looking at an object within the parent document. But when you load a new document, you are loading it into the new window that the iframe generates. So "myfunction()" must be very precise to target the iframe window rather than the parent document.
There are also some user agent complications I've read about. For instance in some browsers (Netscape 6 for example) the onclick event for an iframe element will only fire in on a slim margin around the iframe, and not anywhere else in the iframed document.
But my guess is that the main complication is coming from the exact definition you have of myfunction()
<iframe id="myiframe" name="myiframe"></iframe>
<span onClick="myfunction()">Clickable button</span>
I can keep clicking on the span and it works fine changing the iframe all the time.
What I would like to have done, is it to take effect when the iFrame is clicked on (anywhere inside it) and not have to click somewhere else on the page.