本文介绍了如何使用window.showModalDialog()显示HTML内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够在使用JS的弹出窗口中显示HTML内容(不是文件)吗?

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

我试图打开一个弹出窗口,在其中显示用户定义的HTML。

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.

推荐答案

window.open()相反,第一个(URL)参数是必需的。因此,你不能传递一个HTML字符串。您可以使用 window.open

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>');

或者,使用一个现有的模式插件,例如或。它们允许您根据现有HTML元素的内容轻松显示模式窗口,例如:

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

这篇关于如何使用window.showModalDialog()显示HTML内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:56
查看更多