Create Alert When iFrame is clicked

Discussion in 'JavaScript' started by rbisconti97, Mar 17, 2010.

  1. #1
    I am trying to get this so when I click inside an iframe whose source is from "site1.com" it shows an Alert. I did place the code after the iFrame and it does nothing.
    Here's my code:
    Code:

    <script type="text/javascript">  
    function showAlert(){
    	alert("iframe clicked");
    }
    var elements = document.getElementsByTagName('iframe'); 
    { 
    if(elements.src.indexOf('site1.com')
    { 
    elements.onfocus = showAlert();  
    } 
    } 
    </script>
    Code (markup):
    Thank you
     
    rbisconti97, Mar 17, 2010 IP
  2. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    not possible unless you can change what's inside the iframe. js doesn't permit it crossdomain for obvious security reasons
     
    krsix, Mar 18, 2010 IP