Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I open a window, print, then close window

Status
Not open for further replies.

LonnieJohnson

Programmer
Apr 16, 2001
2,628
US
Hello,

I am new to javascript.

I have an application in asp 2.0.

When a user enters a new record and clicks ok a reciept like document is suppose to print. I want it to go straight to the printer. Someone suggested using javascript to open the document page that has the report document, printing the report and then closing the window all with javascript.

How do I do that? Also, can it be done without a print dialog box? I want it just go to the user's default printer.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
you can print a window by using the [tt]window.print()[/tt] function. you cannot avoid the print dialog box without using an activex control that you'll have to write, and that will still prompt the user because of security concerns.

also, it'd be better to just put a link or a button in the window so the user can click it to close it. closing the window immediately after calling the print function will likely cause undesired effects.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Hmmmm. Ok.

That still puts me in a bind.

When the user enters a new record, there are some options they can click that may make copies of the new record with slightly different info in some fields and can save up to 10 records at once, thus each one will produce a document. Now I have the problem of multiple dialog boxes open or the user having to click something several times. Currently the windows based version of this app does not require them to do this and we were wanting it to be as identical as possible.

Thanks again.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
why not target the links to the same window, then have the window.print() function call on page load? this way, they're clicking the link, then clicking OK when the print dialog box displays.

then, all they'll have to do is click another link and the page will load in the already-opened second window, print again, etc.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Could you keep track of the receipts they need and then provide a button that allows them to print them all at once? Then, you could open just one window like this:
Code:
<style>
body{
  background-color: #CCCCCC;
}
.page {
  filter:shadow(color:gray, strength:5, direction:136);
  width: 300px;
  padding: 5px;
  margin: 5 5 5 5;

}
.page div{
  padding: 10px 10px 10px 10px;
  background-color: white;
  border: solid 1px black;
  height: 200px;
}
@media print{
  .hideOnPrint{
    display:none;
  }
  body{
    background-color: White;
  }
  .page{
    filter:shadow(color:White, strength:0, direction:0);
    page-break-after: always;
    width: 100%;
  }
  .page div{
    padding: 0px 0px 0px 0px;
    background-color: white;
    border: solid 0px White;
  }
}
</style>
<body>
 <form>
  <div align="center" class="hideOnPrint">
    <input type="button" value="Print Receipts" onclick="window.print()" style="width: 300px;">
  </div>

  <div class="page"><div>
    Receipt #1
  </div></div>
  <div class="page"><div>
    Receipt #2
  </div></div>
  <div class="page"><div>
    Receipt #3
  </div></div>
 </form>
</body>

Adam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top