On the webpage I have iframe, in which I display some content.
I want to run a function if any key is pressed inside iframe (iframe is editable).
I can do it using ajax (with scriptmanager on page):
Sys.UI.DomEvent.addHandler(document.getElementById('iframe1').contentWindow.document, 'keyup', iframeKeyHandler);
But I want to do it without ajax!
Updated Code:
function Init() {
document.getElementById('iView').contentWindow.document.designMode = "on";
document.getElementById('iView').contentWindow.document.onkeyup = function(event) {
alert(event);
}
}
<body onload="Init()" >
<iframe id="iView" style="width: 434px; height:371px" ></iframe>
</body>
I guess you meant “do it without using the script manager”?
You can do it this way (use attactEvent/addEventListener):
Or using jQuery’s event handler for “keyup“:
More info on keyboard event arg can be found here and here.