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

javascript - How to display HTML Content using window.showModalDialog() - Stack Overflow

programmeradmin0浏览0评论

Will I be able to display a HTML content (not a file) in a pop up window using JS?

I am trying to open a pop up window and display an user defined HTML inside this. I am trying the below, but it doesn't work.

window.showModalDialog("<p>Pop up window text</p>","resizable: yes");

Can some one suggest me how to do this? Thanks in advance.

Will I be able to display a HTML content (not a file) in a pop up window using JS?

I am trying to open a pop up window and display an user defined HTML inside this. I am trying the below, but it doesn't work.

window.showModalDialog("<p>Pop up window text</p>","resizable: yes");

Can some one suggest me how to do this? Thanks in advance.

Share Improve this question asked Aug 20, 2012 at 10:50 hophop 2,55811 gold badges40 silver badges56 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Contrary to window.open(), the first (URL) argument of showModalDialog() is required. Thus, you can't pass it an HTML string. You can either use window.open:

var newWindow = window.open("", "newWindow", "resizable=yes");
newWindow.document.write('<p>Pop up window text</p>');

Or alternatively, use one the existing modal plugins, such as jQuery UI Dialog or Twitter Bootstrap Modals. They allow you to easily display a modal window based on the content of an existing HTML element, e.g.:

<div id="dialog">
  <p>Pop up window text</p>
</div>

$('#dialog').modal(); // Twitter Bootstrap
$("#dialog").dialog({ resizable: true }); // jQuery UI
发布评论

评论列表(0)

  1. 暂无评论