Xiaodan Mao
Xiaodan Mao

Reputation: 1706

How to create HTML elements dynamically in a popup window?

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?

Upvotes: 5

Views: 32045

Answers (1)

Software Engineer
Software Engineer

Reputation: 3956

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>

Upvotes: 13

Related Questions