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>
10

1 Answer 1

0

You could try:

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

Hope it helps

2
  • 1
    Unsafe, and therefore does not work on many browsers.
    – tekknolagi
    Nov 28, 2011 at 1:23
  • 2
    Note: the iframe's content MUST be from your domain!
    – JCOC611
    Nov 28, 2011 at 1:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.