javascript - How to refresh Javascript code in IFrame?
问题描述
So, I am trying to experiment with making a code editor. I have an IFrame with a preview window that is linked to another HTML document in my webpage where the code would be executed. (I need to execute code with the p5 library) This is the code when I click on "run code" button -
try {
var script = document.createElement( 'script' );
script.id = "code"
script.text = code
$('#preview').contents().find('#codeplaceholder').html(script)
$('#preview').contents().find('#code')
document.getElementById('preview').contentWindow.location.reload();
} catch (e) {
alert(e);
and here is the tags in my HTML preview document:
<!DOCTYPE html>
<html>
<head>
<script id = "p5"
src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.min.js"></script>
</head>
<body>
<div id="codeplaceholder">
</div>
</body>
</html>
so what's wrong? Then I try to run code with the p5 library, nothing happens. I am out of ideas. Seems like "Alert" messages work, but p5 is just really stubborn...
解决方案
推荐阅读
- javascript - 根据下拉框选择显示/隐藏 div
- magento2 - 将 ScandiPWA 安装到现有的 Magento 2 设置
- html - 如何在 Stepper angular 11 材料中对齐表单输入
- heroku - Heroku 应用程序崩溃并显示代码 h10 或找不到模块
- c# - 我想在 JObject 中使用 += 运算符
- flutter - FutureBuilder 不断触发 Future 方法
- javascript - 通过ajax将不同数据类型的参数数组传递给PHP
- javascript - react-redux 默认从 store 中选择值
- go - 使用 grpc 流的聊天应用程序
- docker - 如何使用 docker-compose 将多个 docker 镜像推送到 docker hub?