Ruslan Ruslan -4 years ago 94
Ruby Question

Respond with JS to an iframe file upload

I have an iframe that uploads a file to rails

I want to respond back with javascript. The format that comes in is

html


I tried

<script>
// JS code
</script>


But it loaded a new page and then executed the JS

Key is to upload a file asynchronously and then do more things on the page

Gem remotipart seems nice but i want to keep dependencies low

Answer Source

Look into Window.postMessage() for cross-origin communication. Refer to this post Html5 - Cross Browser Iframe postmessage - child to parent? to learn how to send child-to-parent page messages.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download