I am creating iframes dynamically and I want to prevent scripts that don't originate from the iframes' origin. Is this even possible (via JavaScript/jQuery)? For example, if my page loads an iframe from example.com
with the contents:
<script src="http://example.com/foo.js"></script>
<script src="http://something-else.com/bar.js"></script>
I want the example.com
script to run, but I want the something-else.com
script to be blocked and not run.
I am using NW.js (formerly Node-Webkit), so I have full read-write access to the iframes' contents as if they were same-origin.
I've tried using plugins (like those that bring CORS in the picture, with whitelisting), but nothing I've tried is working.
An ideal solution would also allow me to whitelist specific other origins in addition to the iframe's origin.
EDIT:
Here is my browser project I am trying to implement this in: https://github.com/IdeasNeverCease/Aries
Here is the section of code the iframe loading is done in: https://github.com/IdeasNeverCease/Aries/blob/master/app.nw/resources/scripts/aries.js#L376-L687