Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to feed code into iframe without a URL or FILE?

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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:

<iframe id="my-iframe"></iframe>

<script>
document.getElementById("my-iframe").contentDocument.write("<h1>Hello World</h1>");
</script>

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading