0

I had to run some server side code to open multiple files via javascript something to this effect:

Assume r is just a reader with some data:

If r IsNot Nothing Then
    Dim sb As New StringBuilder()
    Do While r.Read()
        'added below to replace \\ with http://
        strURL = Replace(CType(r("AttachmentLink"), String), "\\myServer\MyFolder\MyPath", "http://MyFolder/MyPath", , , CompareMethod.Text)
        'added below to replace \ with /
        strURL = Replace(strURL, "\", "/")
        sb.AppendLine("window.open('" & strURL & "', '_blank', 'menubar=no');")
    Loop
    ClientScript.RegisterStartupScript(Me.GetType(), "popup", sb.ToString(), True)
End If

This works great for opening multiple attachments... but now I need to not only open them up but print them...

So I tried just taking what I had above and modifying a little:

Do While r.Read()
    'added below to replace \\ with http://
    strURL = Replace(CType(r("AttachmentLink"), String), "\\myServer\MyFolder\MyPath", "http://MyFolder/MyPath", , , CompareMethod.Text)
    'added below to replace \ with /
    strURL = Replace(strURL, "\", "/")
    sb.AppendLine("var oWindow = window.open('" & strURL & "', '_blank', 'menubar=no');")
    sb.AppendLine("oWindow.print();")
    sb.AppendLine("oWindow.close();")
Loop
ClientScript.RegisterStartupScript(Me.GetType(), "popup", sb.ToString(), True)

This of course does not work, no error but nothing comes up. I was hoping to get each window open up and a print dialog from javascript to pop up...

Any ideas?

0

1 Answer 1

0

Due to browser javascript security reasons you're not allowed to print a child window.

What you could do is add a load script into those pages you'd like to print that will initiate printing from that child window instead.

Check this answer that shows a bit different aproach in a sense that:

  1. it creates an iframe
  2. loads some content in it and also
  3. adds onload event to print it...
Sign up to request clarification or add additional context in comments.

2 Comments

Errr...is there any way around this because I've seen people post stuff like this: stackoverflow.com/questions/7187400/…
I dont know how to handle this in my situation :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.