如何在没有URL或文件的情况下将代码馈送到iframe中?
我正在尝试创建一个视觉编辑器,其中用户创建3D场景,而我的应用程序为项目本身编写了代码。我想创建一个测试功能,其中正在运行生成的代码。我已经考虑使用iframes
,但据我所知,您需要一个特定的url
iframe
。
以下是我想到的一些想法/解决方案:
- 是否有一种方法可以将代码手动馈送到
iframe
,而没有文件或URL? - 还有其他更轻松的方法可以完成此任务吗?
- 可以在没有服务器端代码的情况下完成此任务?
让我知道您是否需要更多信息。谢谢!
I'm trying to create a visual editor where the user creates a 3D scene, and my application writes the code for the project itself. I want to create a testing feature where the code that was generated is run. I've looked into using iframes
, but as far as I know, you need a specific URL
for iframe
.
Here are some ideas/solutions I've come up with:
- Is there a way to manually feed code to an
iframe
, without a file or URL? - Is there any other easier way to accomplish this task?
- Can this be done without server side code?
Let me know if you need any more information. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,有可能只需在服务器/主机上的某个地方创建另一个HTML文件,而只是禁止外部访问它,以便只能从
iframe
中访问。您必须使用脚本将代码提供给
iframe
而无需这样的源文件:将javascript更改为
iframe
>:此覆盖:此覆盖
iframe
的所有内容。这将起作用,但要从
iframe
中格式化HTML将是一个很大的痛苦。据我所知,这是适合您需求的最简单方法。Yes it is possible however a much simpler way would be to just create another html file somewhere on your server/host and just disallow external access to it so it's only accessible from the
iframe
.You have to use an script to give code to an
iframe
without a source file like this:Change the JavaScript to this to overwrite all of the content of the
iframe
:This overwrites all the content of the
iframe
with your own.This will work but it will be a big pain to format the html from the
iframe
. Also as far as I know this is the simplest way that fits your needs.