How to create an HTML page dynamically in JavaScript

后端 未结 2 1051
暗喜
暗喜 2021-01-24 22:24

Is it possible to create a full HTML page dynamically in JavaScript?

Basically, I\'m creating an HTML editor in the browser and what I would like to do is have

相关标签:
2条回答
  • 2021-01-24 23:12

    See https://stackoverflow.com/a/10433550/1363613 for a trick ive often used when doing background server communications back in days prior to AJAX kicked in.

    Try creating an IFrame Element, setting a bogus src, append the IFrame to your current Document and then start writing to it (via iframeEl.document.write).

    You need to take into account, that the IFrame document may get closed due to some other external event like timeouts or malformed html etc. So perform the writes in the same javascript function/closure to be sure.

    The technique basically opens an text-input-stream which you may write to via document.write. In turn, a normal loading webpage retreives its source through a websocket-input-stream.

    0 讨论(0)
  • 2021-01-24 23:30

    The closest you can get is an iFrame. You could do other things with c++, c+, c, java, or even python.

    What you should ahve done first however, is googled it. Here is a result that I found for you. CLICK ME! (also a possible duplicate.)

    0 讨论(0)
提交回复
热议问题