|
-
Dec 14th, 2005, 05:20 AM
#1
Thread Starter
Hyperactive Member
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:
Public Sub print()
Dim sc As String
sc = "<script language=JavaScript>"
sc = sc & "window.print();"
sc = sc & "self.close();"
sc = sc & "</script" & ">"
If (Not IsClientScriptBlockRegistered("myprint")) Then
RegisterClientScriptBlock("myprint", sc)
End If
End Sub
Does anybody know what I am doing wrong? Thanx in advance.
Marco
-
Dec 14th, 2005, 05:45 AM
#2
Thread Starter
Hyperactive Member
Re: javascript 'self.close()'
Ok, found the following:
VB Code:
Public Sub print()
Dim sc As String
sc = "<script language=JavaScript>"
sc = sc & "window.print();"
sc = sc & "window.opener='call';"
sc = sc & "window.close();"
sc = sc & "</script" & ">"
If (Not IsClientScriptBlockRegistered("myprint")) Then
RegisterClientScriptBlock("myprint", sc)
End If
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?
-
Dec 14th, 2005, 05:59 AM
#3
Fanatic Member
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.
-
Dec 14th, 2005, 06:05 AM
#4
Thread Starter
Hyperactive Member
Re: javascript 'self.close()'
 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
-
Dec 14th, 2005, 07:11 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|