Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过asp.net在javascript中打开多个弹出窗口_Javascript_Asp.net_Vb.net_Sqldatareader - Fatal编程技术网

通过asp.net在javascript中打开多个弹出窗口

通过asp.net在javascript中打开多个弹出窗口,javascript,asp.net,vb.net,sqldatareader,Javascript,Asp.net,Vb.net,Sqldatareader,我有一个sql datareader,其中有一组路径。 我需要在浏览器上打开多个弹出窗口/多个选项卡。 所以我试着在我的datareader中循环并执行ClientScript.RegisterStartupScript 但是在代码完成后,什么都不会打开 这是我的密码: While r.Read() ClientScript.RegisterStartupScript(Me.GetType, "popup" + counter.ToString(), "window.op

我有一个sql datareader,其中有一组路径。 我需要在浏览器上打开多个弹出窗口/多个选项卡。 所以我试着在我的datareader中循环并执行ClientScript.RegisterStartupScript 但是在代码完成后,什么都不会打开

这是我的密码:

While r.Read()
            ClientScript.RegisterStartupScript(Me.GetType, "popup" + counter.ToString(), "window.open('" + CType(r("AttachmentLink"), String) + "','_blank' + new Date().getTime(),'menubar=no')", True)
            counter += 1
        End While
我放了一块手表在里面,我的阅读器确实包含了我想要的数据,但是没有弹出窗口打开:(

编辑 以下是我的数据库的AttachmentLink列中的一些示例数据:

\\myserver\myfolder\1.pdf
\\myserver\myfolder\mydoc.doc
\\myserver\myfolder\myimage.jpg

实际链接是到存储在我们网络上的本地文件服务器…

这是因为
RegisterStartupScript
的作用域是类型。您是否曾经想过,为什么要提供
类型
参数作为此方法的第一个参数

ASP.NET Framework将此类型用作键,当您第二次尝试添加另一个具有相同类型和相同键的脚本时,它将不会添加它,以防止重复脚本增加HTTP请求(尽管有些浏览器缓存第一个请求,不发送其他类似脚本的请求),但这会降低性能


但是,如果您说实际上什么也没有发生,即使只是一次,我建议您将生成的脚本复制/粘贴到Firebug中,并尝试调试它。

尝试将javascript更改为以下语法:

window.open(url, '_blank', 'menubar=no')
如果这不起作用,请先尝试使用creting脚本,如下所示:

Dim sb as New StringBuilder()
Do While r.Read()
    sb.AppendLine("window.open('" & r("AttachmentLink") & "', '_blank', 'menubar=no');")
Loop
ClientScript.RegisterStartupScript(Me.GetType(), "popup", sb.ToString(), True)
我也注意到,javascript代码中缺少了分号,有时它会把事情搞得一团糟

编辑以添加

回答评论时,您可以使用以下内容:

sb.AppendLine("window.open('" & LoadPageLink(r("AttachmentLink")) & "' ... )")

Function LoadPageLink(path As String) As String
    Return String.Format("loadFile.aspx?p={0}", Server.UrlEncode(path))
End Function

----- LoadFile.aspx

Sub Page_Load(sender as Object, e as EventArgs)
    '*
    '* OK The worst part here is to detect the content-type of the file
    '* because it is being served by a proxy page, instead of directing 
    '* the browser to the actual file, which would make the IIS gess the
    '* content type and send the correct one. 
    '* 
    '* Getting the correct content type is beyond the scope of this answer
    '*

    Dim buffer as Byte(1024)

    Using (stream as New FileStream(Request("p")))
        Do While True
           Dim read = stream.Read(buffer, 0, buffer.Length)
           If (read > 0) Then
               Response.OutputStream.Write(buffer, 0, read)
           Else
               Exit Do
           End If
        End Do
    End Using

End Sub

所以我猜我还有什么其他选择?看这个,显然是有人想出了办法,但对我来说不起作用。代码正在更改密钥。
“popup”+counter.ToString()
部分。@Saeed还看了第二个参数,它不是同一个密钥。我几乎认为,问题在于r(“AttachmentLink”)指的是本地服务器上的一个文件,如“\\myserver\attachments\mydoc.doc"所以当我这样做的时候,我会得到一个“未找到”,因为我认为它会将主机转换为“啊哈…”这可以解释很多…:Pis有什么办法吗?好吧,你需要更改数据库中的位置,这样它就指向一个合适的位置,或者你可以编写一个包装器。我马上会添加类似的内容,但它是一个合适的位置,它是我们文件中的一个文件电子服务器。