javascript - Listen for keydown events in iframe with cross-domain -


i want listen keydown events in iframe stop backspace being executed. works long page in iframe comes same domain, when comes domain fails when contents() method called.

the error is:

ie: "0x80070005 - javascript runtime error: access denied."

chrome: "uncaught securityerror: failed read 'contentdocument' property 'htmliframeelement': blocked frame origin "domain_a" accessing frame origin "domain_b". protocols, domains, , ports must match."

is there way listen keydown events on iframes domain?

i use angularjs code setup listener:

keydownservice.prefilterkeydown($(this).contents()); ... angular.module('portal.services.keyhandlers.keydownservice', []) .service('keydownservice', function () {     //prevents shortcut keys (for instance backspace) in being executed in iframe or document.     this.prefilterkeydown = function ($document) {         $document.keydown(function (e) {             var preventkeypress;             switch (e.keycode) {                 case 8: //backspace                     preventkeypress = preventbackspace(e);                     break; ...                 default:                     preventkeypress = false;             }              if (preventkeypress)                 e.preventdefault();         });     } 

no. cannot , has nothing angularjs. security violation prevent iframe-ing in bank of america own site , stealing user's credentials frame.

however, if control both pages can have iframe voluntarily provide data back. postmessage common technique:

http://caniuse.com/#search=postmessage

essentially trap keystrokes in iframe , send message parent details. browsers allow because it's voluntary , cooperative - have control both sender , receiver, can't used steal user without them knowing it.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -