avatar
avatar

Reputation: 12495

jQuery - focus inside an iframe?

I'm using a wysiwug jQuery plugin that creates an iframe for my textarea like this:

<div class="wysiwyg" style="width: 581px;">
<ul class="panel" role="menu">
<div style="clear: both;"></div>
<iframe id="id_message_bodyIFrame" frameborder="0" src="javascript:false;" style="min-height: 170px; width: 573px;" tabindex="0">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body style="margin: 0px;">
DETECT WHEN I START TYPING TEXT HERE <--------
</body>
</html>
</iframe>
</div>
<textarea id="id_text_area" name="message_body" cols="70" rows="10" style="display: none;"></textarea>
</div> 

I want to be able to detect when I start typing text inside of the body of the iframe, something like focus() does on text inputs. Any ideas?

Upvotes: 2

Views: 8919

Answers (1)

mattsven
mattsven

Reputation: 23283

var frameBody = $("#id_message_bodyIFrame").contents().find("body");

frameBody.focus(function(){ /* ... */ });
frameBody.click(function(){ /* ... */ });
frameBody.keyup(function(){ /* ... */ });

Upvotes: 5

Related Questions