Results 1 to 5 of 5

Thread: javascript 'self.close()'

  1. #1

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    javascript 'self.close()'

    Hello all,

    I've got an ASPX page that pops up in a new window (via javascript) in my browser when I click a hyperlink on a page. I want to print it automatically, causing the user to select a printer. That part works. After that, I want to automatically close that window. That part doesn't work. From my Page_Load event, I run this code:

    VB Code:
    1. Public Sub print()
    2.         Dim sc As String
    3.         sc = "<script language=JavaScript>"
    4.         sc = sc & "window.print();"
    5.         sc = sc & "self.close();"
    6.         sc = sc & "</script" & ">"
    7.         If (Not IsClientScriptBlockRegistered("myprint")) Then
    8.             RegisterClientScriptBlock("myprint", sc)
    9.         End If
    10.     End Sub

    Does anybody know what I am doing wrong? Thanx in advance.

    Marco

  2. #2

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Re: javascript 'self.close()'

    Ok, found the following:

    VB Code:
    1. Public Sub print()
    2.         Dim sc As String
    3.         sc = "<script language=JavaScript>"
    4.         sc = sc & "window.print();"
    5.                          sc = sc & "window.opener='call';"
    6.         sc = sc & "window.close();"
    7.         sc = sc & "</script" & ">"
    8.         If (Not IsClientScriptBlockRegistered("myprint")) Then
    9.             RegisterClientScriptBlock("myprint", sc)
    10.         End If
    11. End Sub

    Only now, the 'print' dialog is shown, but the rest of the code after window.print() runs at the same time, resulting in not closing the browser page. Is there a way to let the code 'wait' after window.print() call?

  3. #3
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    Re: javascript 'self.close()'

    im not sure on the whole thing but
    could you not do them in 2 seperate sub procedures and call them one after each other
    public sub print()
    ...................
    public sub close()
    ...................

    print()
    close()

    it might work, it might not lol
    it works 60% of the time, all the time.

  4. #4

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Re: javascript 'self.close()'

    Quote Originally Posted by d2005
    im not sure on the whole thing but
    could you not do them in 2 seperate sub procedures and call them one after each other
    public sub print()
    ...................
    public sub close()
    ...................

    print()
    close()

    it might work, it might not lol
    it doesn't work. Same problem: the close() method is called right after the print(), not waiting for me to select the printer.

    Now, I have built in an invisible button, from which I call the click event in Form_Load, right after the print() function. Now, the print dialog is not shown, and the browser window is directly closed. I need a way that the system waits until I have selected whether or not to print...

    Anyway, thanx

    Marco

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: javascript 'self.close()'

    What version of IE are you using? It works fine for me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width