Log In · Register

 
 
Closed TopicStart new topic
javascript onclick with iframe
heyo-captain-jac...
post Apr 11 2010, 09:02 PM
Post #1


/人◕‿‿◕人\
*******

Group: Official Member
Posts: 8,283
Joined: Dec 2007
Member No: 602,927



I need to make it so a javascript onclick alert works whenever I click in an iframe.

CODE
<iframe src="http://example.com" name="frame1" scrolling="auto" frameborder="no" align="center" height = "100%" width = "100%" onClick="alert('test')";>
</iframe>


that's just not working for some reason. It's probably something really simple keeping it from working too.
 
fixtatik
post Apr 12 2010, 08:13 AM
Post #2


Senior Member
******

Group: Member
Posts: 1,237
Joined: May 2008
Member No: 648,123



The really simple thing is that the onclick attribute doesn't exist for iframes. You get to make use of onload instead, something like this:
CODE
<iframe onload="this.contentWindow.document.onclick=function(){alert('test')}"></iframe>

.contentWindow is self-explanatory: the contents of the current iframe.
 

Closed TopicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members: