window.close doesn't work after window.print

Posted on 2003-03-25
Medium Priority
Last Modified: 2008-01-09
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

Question by:Sathishwar
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 23

Expert Comment

by:Saqib Khan
ID: 8204344
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.

Author Comment

ID: 8204393
It did not work. First of all document.print() doesn't work. self.close() has same effect as the window.close().

LVL 23

Expert Comment

by:Saqib Khan
ID: 8204544
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>
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

LVL 10

Expert Comment

ID: 8204649
how about window.close(this)

Author Comment

ID: 8204665
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.

LVL 23

Expert Comment

by:Saqib Khan
ID: 8204721
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?

Author Comment

ID: 8205168
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
LVL 23

Accepted Solution

Saqib Khan earned 200 total points
ID: 8205480
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.

Author Comment

ID: 8220065
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.

LVL 16

Expert Comment

ID: 10149824
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.

EE Cleanup Volunteer

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question