Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 537
  • Last Modified:

window.close doesn't work after window.print

I have button that does 'window.print()', and other button to close the window('window.close()'). If i click on Print button and them close button then close window doesn't work.
Looks like window.close is not working after window.print().

Any solution/work around for this problem? I'm using IE 5.5

Sathish
0
Sathishwar
Asked:
Sathishwar
1 Solution
 
Saqib KhanSenior DeveloperCommented:
Lets say you have two butttons one is Print and the other is Close, make sure you have the following code on them.



<a href="javaScript:document.print()">Print</a>

and for Close

<a href = "javaScript:self.close()">Close</a>

it should work fine. if it does not please let me know.
0
 
SathishwarAuthor Commented:
It did not work. First of all document.print() doesn't work. self.close() has same effect as the window.close().

Sathish
0
 
Saqib KhanSenior DeveloperCommented:
here is what worked for me. I just tried it

<a href="javaScript:window.print()">Print</a>




<a href="javaScript:self.close()">Close</a></p>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BustaroomsCommented:
how about window.close(this)
0
 
SathishwarAuthor Commented:
Yes...that worked.
Let me explain how i'm doing here because it's slightly different from what you did. Sorry for not explaining it first time itself.

I have print button, and a close button.

print button just has "window.close()" but in case of close button, i'm submitting the form to same page and when it reloading the page due to the submit, it does some other server-side stuff and submits the parent window and executes window.close(). This is what is failing.

Do you see any problem in above process?

Thanks so much for your help.

Sathish
0
 
Saqib KhanSenior DeveloperCommented:
so you have a Print button and what Action did you assign to Print button? and what exactaly you want to do on Form submit? and when you want to or not want to close the window?
0
 
SathishwarAuthor Commented:
Oops...I meant 'print button just has "window.print()" ' not "window.close()".

I want to process the submit on that same page before closing that window when user clicks on close button.

Bottom line is... i want following stuff on my page.

print - just prints the page
close - does some server-side stuff & closes the window
0
 
Saqib KhanSenior DeveloperCommented:
Really I think You can not do this on the same page by using javaScript. I mean first of all somehow you need to reload the page to insert/update for your serverSide Stuff then Invoke any other function. What I would recommend is just make another page and do your server side scripting on that newpage. And when user Clicks Close Button Redirect them to that new page, and on that new page you can Close your window without user interaction.
0
 
SathishwarAuthor Commented:
I'm doing all that stuff that you described above. I explained only the required part when i explained to you. I explained only the javascript side of the code.

I tried with having server-side in different page, and closing the window from that page etc... almost all the possible combinations...everyone of them had same effect.

I think it's nothing to do with what page is inside that window... i heard that there is known bug around window.close after window.print in IE5.x.

I tried same code in IE6.0 and it worked just fine.

Sathish
0
 
jaysolomonCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: adilkhan {http:#8205480}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now