Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create HTML elements dynamically in a popup window?

Tags:

javascript

Previously,I used the window.showModalDialog() function to popup a window:

window.showModalDialog("myHtml")

In myHtml,there are some html elements,like the textarea and two buttons. But now the situation changed,any html file is not allowed.So I have to create the html elements dynamically in the popup window.Is it possible?

like image 890
Xiaodan Mao Avatar asked Mar 23 '12 09:03

Xiaodan Mao


1 Answers

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>
like image 108
Coder Avatar answered Nov 01 '22 10:11

Coder