Reputation: 7253
I'm working on a Greasemonkey script for gmail and I need to find a way to refer to gmail's textboxes (when you compose and reply to an email). Gmail has an iframe with a new HTML and the text is in the body, as part of it's WYSIWYG editor. I've tried selecting all the classes of those elements with jquery, but they don't work -- specially, .keypress()
Here's what I have tried:
$(".editable LW-avf").keypress(function(event) {
... // the wysiwyg body
});
$(".Am Al editable").keypress(function(event) {
... // the iframe
});
Is there any way to bind a keypress event handler? Or is it even possible since gmail isn't a conventional textbox?
Upvotes: 3
Views: 441
Reputation: 93493
(".editable LW-avf")
would select not <body class="editable LW-avf">
.
It would select something like:
<div class="editable">
<LW-avf></LW-avf>
</div>
If that existed.
You want:
$("body.editable.LW-avf")
(Two classes, two dots in the selector.)
Also:
keydown
, not keypress
, for your purposes.Upvotes: 2
Reputation: 3798
It's not pretty but it does the job:
document
.querySelector(".editable")
.contentDocument
.querySelector(".editable")
.onkeypress = function() { alert("jayer!"); };
Upvotes: 1