I'm making a very simple Rich Text Editor using jquery... I don't want to use a third-party one.
I need to listen for events within an iframe (same domain etc), starting with typing. Apparently I'll need to use bind() a lot.
This is what I've got at the moment which works fine in IE8 (amazingly enough) but not Chrome.
<script>
$(function() {
$('#text').contents().bind("keyup keydown keypress", function(e) {
var code = e.keyCode || e.which;
alert(code);
return false;
});
});
</script>
<body>
<iframe id="text" name="text" src="edit.html"></iframe>
</body>
On the key press event above, I will also want to get the current value of 'edit.html' and update a textarea with that value...
Any help would be MUCH appreciated :)
Many thanks
EDIT: to explain further, edit.html is an editable file using "document.body.contentEditable = true;"
-
EDIT 2:
edit.html =
<script language="javascript">
function InitializeIFrame() {
document.body.contentEditable = true;
}
</script>
<html>
<body onload="InitializeIFrame();">
</body>
</html>
current value
u mean thesrc
value which is = "edit.html" if so$('#text').attr('src');
returns edit.html – Breatherconsole.log(whatever);
. Besides, I'm sure that's only temporary? – Stoushvar log = function (str){ console.log(str) }
only put that once :) then use it aslog(watever)
– Breather$('#text').contents().find('body,html').bind....
and let me know if that does the trick, btw body,html is for cross browser :) – Breather