问题描述
这可能很简单,但我还没有找到任何简单的解决方案.
This could be a simple but I havent found any easy solution.
在 asp.net 网页中单击按钮单击事件 html 是从 xml 和 xsl 生成的.此 html 存储为字符串变量.例如让我们说
On clicking button in asp.net web page on button click event html is generated from xml and xsl. This html is stored as string variable. For example lets say
dim htmlString as string = "<div>This is my popup</div>"
从上面的 html 字符串如何在 vb.net 中动态创建 html 弹出窗口.我可以使用 javascript 在前端创建弹出窗口,但还没有找到通过 vb.net 中的代码隐藏文件创建它的任何解决方案
From the above html string how can I dynamically create html popup window in vb.net. I can create popup window on front end by using javascript but havent found any solution to create it through code behind file in vb.net
这在 IE 中不起作用,只在 firefox 中起作用:
This does not work in IE, only works in firefox:
Dim popupScript As String = _
"<script language='javascript'> myPopup() </script>"
Dim mystring = "<html><body><div style=""color:black"">Name: Jame's</div></body></html>"
Page.ClientScript.RegisterStartupScript(Me.GetType(), "PopupScript", String.Format(popupScript))
推荐答案
你只能用javascript创建一个弹出窗口,所以你需要从codebehind注册那个脚本:
You can only create a popup-window with javascript, so you need to register that script from codebehind:
ClientScript.RegisterStartupScript(Me.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", url))
也许我误解了你的要求.您不仅想从代码隐藏中打开客户端弹出窗口(window.open
),还想在没有 url 的情况下即时创建该窗口?
Maybe i've misunderstood your requirement. You want not only to open a client-side popup(window.open
) from codebehind but also create that window on the fly without url?
也许这有帮助(未经测试):
Maybe this helps(untested):
Dim popupHtml = "<html><body><div style=""color:black"">Name: Jame's</div></body></html>"
Dim openPopupScript = "NewPopup=window.open("", 'newWindow', 'height=250, width=250');" & _
"NewPopup.document.open();" & _
String.Format("NewPopup.document.write('{0}');", popupHtml) & _
"NewPopup.document.close();"
ClientScript.RegisterStartupScript(Me.GetType(), _
"newWindow", _
openPopupScript)
这篇关于来自文件后面代码的 Html 弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!