有人能指出我正确的方向
我需要一个代码来动态创建一个临时的Web弹出页面,我将在ASP.NET中使用VB声明HTML内容
这个功能的原因是我正在尝试制作应用程序表单打印机,我需要打印当前页面
<script>window.print();</script>
您可以将整个HTML生成为字符串,然后使用如下:
window.open("data:text/html;charset=utf-8,<head></head><body><h3>Test Document</h3></body><script>window.print();</script>");
基本上,
window.open("data:text/html;charset=utf-8," + YOUR_HTML + "<script>window.print();</script>");
复制粘贴以下脚本在浏览器中测试:
data:text/html;charset=utf-8,<head></head><body><h3>Test Document</h3></body><script>window.print();</script>
==更新== Aspx.vb代码
Dim htmlText As String = "<head></head><body><h3>Test Document</h3></body>".Normalize()
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "tempWindow", "<script>openTempWindow('" + htmlText + "')</script>", False)
Aspx代码
<script type="text/javascript">
function openTempWindow(content) {
var win = window.open("");
win.document.write(content);
}
</script>
你可以通过操纵qazxsw poi来实现这一点。这是动态创建HTML文档的一种方法。例如:
response
为了使它成为一个弹出窗口,你可以在你的基页中实现HttpContext.Current.Response.Write("<html>
<body>
<h1>Something to print</h1>
</body>
<script>window.print();</script>
</html>")
函数,比如按一下按钮。例如:
window.open()
在提供的链接中,您可以找到有关如何打开窗口作为弹出窗口的更多示例,其中包含大小等设置。