最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to create HTML elements dynamically in a popup window? - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question asked Mar 23, 2012 at 9:36 Xiaodan MaoXiaodan Mao 1,7062 gold badges17 silver badges32 bronze badges 3
  • where is this method defined (showModalDialog), are you using a library maybe ? – Tom Commented Mar 23, 2012 at 10:25
  • 1 This is very basic JavaScript, I hardly believe you couldn't find any documentation on the subject. For instance – Madara's Ghost Commented Mar 23, 2012 at 10:45
  • 1 Yeah,you are right,you make me feel ashamed,self thinking is needed. – Xiaodan Mao Commented Mar 25, 2012 at 13:00
Add a comment  | 

1 Answer 1

Reset to default 13

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>
发布评论

评论列表(0)

  1. 暂无评论