I have an iframe with designMode=”on” (Yeah – I know this is bad thing)
I should catch clicking on it and keypressing and echo the node name of target element.
$(function() {
var editor = $("#editor")[0].contentWindow;
var doc = editor.document;
editor.document.designMode = "on";
doc.open();
doc.write('<div id="dummy">test</div>');
doc.close();
// find iframe body
var $body = $("#editor").contents().find('#dummy').parent();
// clean after finding
$body.html('<div>Hello</div>');
var report = function(e) {
$("#result").html(
$("#result").html() + " " + e.target.nodeName.toLowerCase());
};
$body.click(report);
// $body.keypress(report) -> doesn't work
// only $(doc).keypress works:
$(doc).keypress(report);
});
When I click on word “Hello” – I get “div” – it’s correct, but when I keypress on it – i get “html” instead “div”. How to fix this?
I did a bit of google .. this might help you:
all credis to jetcook (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_25589672.html)