2

Possible Duplicate:
How to add click event to a iframe with JQuery

I am trying to add a click event to my iframe but it does not seem to work?

code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

    <script type="text/javascript">

        $('#iframe_id').bind('click', function (event) { alert('hi'); });

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <iframe id="iframe_id" src="http://www.google.com"></iframe>
    </div>
    </form>
</body>
</html>
Community
  • 1
  • 1
Pindakaas
  • 4,389
  • 16
  • 48
  • 83

1 Answers1

0

You could try:

document.getElementById("iframe_id").contentWindow.document.body.onclick = 
function() {
  alert("iframe clicked");
}

Hope it helps

Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162