How to display HTML Content using window.showModalDialog()(如何使用 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()
相反,showModalDialog()
是必需的.因此,您不能将 HTML 字符串传递给它.您可以使用 window.open
:
var newWindow = window.open("", "newWindow", "resizable=yes");
newWindow.document.write('<p>Pop up window text</p>');
或者,使用现有的模态插件之一,例如 jQuery UI Dialog 或 Twitter 引导模式.它们允许您根据现有 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 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 window.showModalDialog() 显示 HTML 内容


基础教程推荐
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01