admin管理员组

文章数量:1403522

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="">
<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?

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/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?

Share Improve this question asked Apr 25, 2011 at 22:19 avataravatar 12.5k17 gold badges71 silver badges82 bronze badges 2
  • I don't think focus() works on anything other than form elements or links. – Mottie Commented Apr 25, 2011 at 22:27
  • @fudgey Are there any other ways to acplish the same thing without the focus ()? – avatar Commented Apr 25, 2011 at 23:39
Add a ment  | 

1 Answer 1

Reset to default 5
var frameBody = $("#id_message_bodyIFrame").contents().find("body");

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

本文标签: javascriptjQueryfocus inside an iframeStack Overflow