There is a form

<form id="s-plugin-cml1c-import" method="post" action="?plugin=cml1c&action=upload" enctype="multipart/form-data" target="s-plugin-cml1c-import-iframe"><input type="file" name="files"></form> 

and there is a frame where the result of processing the form is loaded

 <iframe name="s-plugin-cml1c-import-iframe" id="s-plugin-cml1c-import-iframe"></iframe> 

In my js I'm trying to get the data from the form uploaded to the iframe

 $('#s-plugin-cml1c-import-iframe').load(function (e) { try { console.log($(this).contents()); } catch(e) {...} 

After calling $(this).contents() gives the error:

"The content from the HTMLDFrameElement": Blocked a frame with origin " http://baby-upgrade.ru " from accessing a cross-origin frame.

Everything happens within a single domain. What could be the problem?

    1 answer 1

    It describes a very similar problem: https://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame

    Recommend using Window.postMessage () https://developer.mozilla.org/ru/docs/Web/API/Window/postMessage

    Express description can be found here https://learn.javascript.ru/cross-window-messaging-with-postmessage .

    Usage example

    Simply put, if we want to send a message to the win window, then we need to call win.postMessage (data, targetOrigin).

    • In these solutions, the data is transferred from the main window to the frame. And I need to get the data from the frame to the main window. So the postMessage option is not suitable. - Andrey
    • Please try to publish detailed answers containing a specific example of the minimum solution, supplementing them with a link to the source. Answers –references (as well as comments) do not add knowledge to the Runet. - Nicolas Chabanovsky
    • Ok, agreed - Anton Kovylin