I have an IFrame with designMode = "on" (yes - I know this is a bad thing) Let me click on it and do the quiking and echo the node name of the target element. When I "Hello" I click on - I get "div" - that's right, but when I press it - I get "html" instead of "div". How to fix it? I've done a little bit Google. It can help you: All credits for JetKook (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_25589672.html)
$ (function () {var editor = $ ("# editor") [0] .contentWindow; var doc = editor.document; editor.document.designMode = "on"; doc .open (); doc.write ('& lt; div id = "dummy"> test ;); doc.close (); // iframe body var $ body = $ ( Find the content (). ('# Dummy'). After removing $ body, parent (); // clear html ('
< Code> var f = document.getElementById ('iframe_id'); Var fwin = f.contentWindow || F.contentDocument; Fwin.document.designMode = 'on'; Var evt_key = function (e) {e = e || Fwin.event; Var range = zero, ret = null; If (fwin.document.selection) {range = fwin.document.selection.createRange (); Ret = range.parentElement (); } And if (fwin.window.getSelection) {var category = fwin.window.getSelection (). GetRangeAt (0); Ret = range.common ESTNT CONTAINER. ParentNode || Fwin.document; } Fwin.parent.do_some_thing (ret); }; If (fwin.document.attachEvent) {fwin.document.attachEvent ('onkeypress', evt_key); } And if (fwin.document.addEventListener) {fwin.document.addEventListener ('keypress', EVT_key, false); }
Comments
Post a Comment