javascript - 将代码隐藏中的字符串输出到新页面或窗口

标签 javascript html asp.net vb.net

假设代码后面有一个字符串变量,其中包含一些 HTML 内容,例如

Dim str1 As String = "<h3>hello</h3><p>some paragraph</p><table><tr><td>some table content</td></tr></table>"

可以通过注册脚本来打开保存的文件,例如

Dim script1 As String = "window.open('popupPage.html', 'myPopup')"
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "someId", script1, true)

有没有办法从代码隐藏中在新选项卡或窗口中输出此内容而不将其保存到文件中?

最佳答案

您可以传递一个空字符串作为文件名

'Declare a script with your variable
Dim script1 As String = "<script>var popwin = window.open('','myPopup');popwin.document.write('" & str1 & "');</script>"

'Call your script with ScriptManager for async postback from UpdatePanel
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "poptest", script1, true)

'Call your script with ClientScript for synchronous postback outside/without UpdatePanel
ClientScript.RegisterStartupScript(Me.GetType, "popuptest", script1, True)

检查这个Call javascript function from asp.net code behind after server side code executes

关于javascript - 将代码隐藏中的字符串输出到新页面或窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33191303/

相关文章:

javascript - Google Maps API InfoWindow 中按钮的监听器以获取方向

javascript - 使用 jQuery 只选择默认的 block 级元素

javascript - 需要帮助修复 Javascript 中的无限循环

javascript - 带有 ID 的 HTML 样式类?

javascript - 调整 div 垂直或水平大小

.net - 跨 DMZ 的代理调用

javascript - 排除正则表达式模式中仅由制表符组成的空格

php - 这是什么编码?

c# - 如何以编程方式在 Sitecore 中创建用户配置文件

javascript - Context2d arc() 带有开始路径,生成奇怪的圆圈