How to dynamically create HTML elements in a popup?

I used to use the window.showModalDialog () function for a popup:

window.showModalDialog("myHtml") 

There are some html elements in myHtml, such as textarea and two buttons. But now the situation has changed, any html file is not allowed. Therefore, I need to dynamically create html elements in a popup. Is it possible?

+4
source share
1 answer

The following code works for me:

 <script type="text/javascript"> function createPopup(){ var popup = open("", "Popup", "width=300,height=200"); var txtOk = popup.document.createElement("TEXTAREA"); var aOk = popup.document.createElement("a"); aOk.innerHTML = "Click here"; popup.document.body.appendChild(txtOk); popup.document.body.appendChild(aOk); } </script> 

To call, use:

 <div id="divPopup" onclick="createPopup();">Create popup</div> 
+12
source

Source: https://habr.com/ru/post/1403041/


All Articles