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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing in .asp

Status
Not open for further replies.

OhioSteve

MIS
Mar 12, 2002
1,352
US
I am using classic asp on my intranet web site. The users view this site with IE. I want to load a page for a brief instant, then I want to send that page to the printer, and finally I want to redirect the user to another page. I know about using "response.redirect..." to redirect them after the first page loads and prints.

How do I automatically send the print job? I know how to create a print button, but in this case I don't want a button- I just want it to print automatically.
 
Thanks for your feedback. I tried inserting your code, and it summoned a print dialogue box. Unfortunately, I need instantaneous printing, not a dialogue box.

Perhaps I could combine your code with sendkeys. I don't know the exact syntax for that, but I will experiment.
 
Check this thread thread215-882172 for an answer, it may not be the only answer, but it works in IE.

TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
What I do is I have a <div id='printReady'> tag to wrap the total area on the page that I want to be printed when you click on the print button I put on the page.


Code:
<script language="JavaScript">
var gAutoPrint = true; // Flag for whether or not to automatically call the print function

function printSpecial()
{
	if (document.getElementById != null)
	{
		var html = '<HTML>\n<HEAD>\n';

		if (document.getElementsByTagName != null)
		{
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}
		
		html += '\n</HE' + 'AD>\n<BODY>\n';
		
		var printReadyElem = document.getElementById("printReady");
		
		if (printReadyElem != null)
		{
				html += printReadyElem.innerHTML;
		}
		else
		{
			alert("Could not find the printReady section in the HTML");
			return;
		}
			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';
		
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();
			printWin.close();
	}
	else
	{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}

</script>


What this does is opens another window briefly with what I want printed, then it opens the printer dialogue for you to choose which printer, how many pages etc. Once you print, the new window closes.

&quot;Every day is like a precious gift, you have to make it count&quot; James Birrell 1993-2001
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top