I am trying to get something similar working as JSFiddle, where a user can enter js, css, and html code, and it will be rendered in a sandboxed iframe.
The path to the JQuery file works when I call it in the parent html file, and when I use the same url within the iFrame I do not get a 404 error.
I have tried both relative and full paths:
<script type="text/javascript" src="http://localhost:3000/javascripts/jquery-3.1.0.min.js"></script>
I can even open the jquery file within the iframe using the same url! /javascripts/jquery-3.1.0.min.js
I have gone through each of the solutions in this SO post, but none resolves the issue.
When I try to execute jquery within the iframe with sandbox settings I get an error:
Uncaught ReferenceError: $ is not defined
Please note I am also getting this warning (in case it is having an effect):
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
which the console link is showing this (from jquery's minified file):
....ajaxTransport(function(b){var c,d;return o.cors||Pb&&!b.crossDomain?{send...
I am not aware of any other ajax running, so at this point I'm not sure where the conflict is originating from.
html:
<iframe name="result" sandbox="allow-popups allow-scripts allow-same-origin allow-modals" frameborder="0" class="sandboxed" style="height: 0px; overflow-y: hidden; min-height: 300px;">
#document
<html>
<head>
<script src="/javascripts/jquery-3.1.0.min.js"></script>
<style type="text/css">
.test { display:inline-flex; padding-top:10px; padding-bottom: 10px; padding-left: 40px; padding-right: 40px; background-color:#cccccc; color:white; justify-content:center; align-items:center; font-size:20pt; font-weight:lighter; font-family: sans-serif }
</style>
<script type="text/javascript">//<![CDATA[
$('.test').text('works');
//]]>
</script>
</head>
<body>
<div class="test">test</div>
</body>
</html>
</iframe>
Any help is appreciated!