Print This Page Button (Full Version)

All Forums >> [Community] >> OutFront Discoveries



Message


hhammash -> Print This Page Button (9/29/2002 17:53:06)

How to Make a Button That Prints the Page


This script will create a " Print Button" that when clicked on your site will print the page it is placed on. It has been tested in MSIE 4 and 5 and NN 4+ browsers.

This entire script below goes in the <BODY> section where you want your button to appear on your page.


<SCRIPT Language=" Javascript" >

function printit(){
if (NS) {
window.print() ;
} else {
var WebBrowser = ' <OBJECT ID=" WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID=" CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" ></OBJECT>' ;
document.body.insertAdjacentHTML(' beforeEnd' , WebBrowser);
WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = " " ;
}
}
</script>

<SCRIPT Language=" Javascript" >
var NS = (navigator.appName == " Netscape" );
var VERSION = parseInt(navigator.appVersion);
if (VERSION > 3) {
document.write(' <form><input type=button value=" Print this Page" name=" Print" onClick=" printit()" ></form>' );
}
</script>


Regards
Hisham





Charles W Davis -> RE: Print This Page Button (9/30/2002 13:32:50)

Hisham,

As you indicated the print button does work in IE and NN. However, it just stares back at you in Opera 6.




abbeyvet -> RE: Print This Page Button (9/30/2002 20:58:07)

This one is a bit shorter and as far as I know works in all browsers:

<Script language=" JavaScript" >
if (window.print) {
document.write(' <form>'
+ ' <input type=button name=print value=" Print Page" '
+ ' onClick=" javascript:window.print()" > </form>' );
}
</script>




imouthere -> RE: Print This Page Button (9/30/2002 22:23:12)

I' ve always just used this text link print ...
quote:

<a href=" #" onClick=" window.print()" >Print Page</a>


Best of Luck,




ccmoran -> RE: Print This Page Button (10/5/2002 11:20:35)

How is a " printer friendly" version of the hyothetical page set up?

Cathy




abbeyvet -> RE: Print This Page Button (10/5/2002 12:01:06)

It really depends how your original pages are created.

If they are plain HTML then the only way is to manually create an extra page. If they are called from a database then you can just set up a simple page that also calls them.

If it was just a few pages you could put the content into an include page and include it in both the standard and for printing pages. At least that way you would have only one page to edit if you wanted to change something.




monsieurrick -> RE: Print This Page Button (10/17/2002 15:42:48)

i was wondering if you could modify this script to limit the number of prints as in one test and one actual. i have a need for such. thanx, rick




hhammash -> RE: Print This Page Button (10/23/2002 13:33:17)

Hi,

Thank you all for your input.

You made it a rich subject.

This back button will not be put on the index page. I usually put it on my site where the reader views series of pictures or reads more than one page. The second page will send him back to the first page where he/she came from. When the user reaches the first page he/she will not have the button.

Thanks you again for your ideas. They are all useful.

Regards
Hisham




Avick -> RE: Print This Page Button (1/20/2005 6:55:27)

I am using the javascript:window.print() command along with a print style sheet (for screen I use the sheet screen.css and for print I use print.css)

Is there any way I can use the javascript:window.print() to preview the page. I have tried
javascript:window.print() but its not working. (worth a try though [:)])

I think I recall seeing this before but can't remember where.





Kitka -> RE: Print This Page Button (1/20/2005 7:16:06)

Avick,
You might try:
<html>
<head>
<title>Print Preview</title>
<script>
function printpr()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/
var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
}
</script>
</head>
<body>
<form>
<input type='button' value="Print Preview" onclick="printpr();">
</form>
</body>
</html>




Avick -> RE: Print This Page Button (1/20/2005 7:39:54)

Thanks Kitka.

It worked fine when I put it in but I decided to take it out as I want to keep the JS to a min.

Worth keeping on file





Karl -> RE: Print This Page Button (1/20/2005 8:07:41)

All,

I usually use:
<a id="gotoprint" href="javascript:window.print();" title="Print page">Print page</a>


Cathy,

In response to your question:

quote:

How is a " printer friendly" version of the hyothetical page set up?


When building your site, you can link to an external style sheet while setting the media to "print".

Par example: 
<style type="text/css" media="print">@import "print.css";</style>


Have a look at this post in the CSS Forum: Print pages using CSS

HTH,

Karl




d a v e -> RE: Print This Page Button (1/20/2005 9:20:57)

doesn't averyone have a print button/menu commanc/shortcut in their browser ?!

;)

i've always been at a loss as to why people put those on their pages, but hey that's me!




Avick -> RE: Print This Page Button (1/20/2005 9:25:30)

Most people put them on there pages because most web pages don't fit on A4 or Letter paper.
When you put a button or link like this on the page you are telling the visitor. This page was designed to be printed on to paper.





d a v e -> RE: Print This Page Button (1/20/2005 9:35:00)

of course - forgot that, but with a print style sheet there's no need :)




Avick -> RE: Print This Page Button (1/20/2005 11:10:39)

But how do they know you have a print stylesheet unless you put *Print Version* on your site [;)]

Most people would just look at the page and say "Well I'm not printing that"


Forgot this but:
Have a look at my terms page http://www.newebirl.net/terms.htm now click the print version and print the page (2pages) see the differance.




d a v e -> RE: Print This Page Button (1/20/2005 12:10:29)

fair point - but what if they have js disabled? well then i guess they just print and the styleheet takea care of it anyway :)

nice site by the way




Avick -> RE: Print This Page Button (1/20/2005 16:49:55)

Thanks David

and your right, if JS is disabled that the sheet still works.
The words print version still apper in the screen version regardles of the JS so they know thy can print that page.

So now you have seen the light are we going to see a print version on your site [:D]




d a v e -> RE: Print This Page Button (1/21/2005 0:17:38)

my 'site' (in my sig) is so small that i don't need a print version - thw whole thing fits on a stamp (well almost) i need to finish it one day. i did do a print style sheet for my last site
http://flaxandhemp.bangor.ac.uk/




Avick -> RE: Print This Page Button (1/21/2005 5:11:38)

A welsh site, very nice. Had to click the English section as I don't know welsh.
Fantastic Country. Stopped off there on my way to Coventry. Breath Taking!!!





d a v e -> RE: Print This Page Button (1/21/2005 7:20:16)

i lived in bangor (North Wales, near Snowdon) for 4 years and it's really nice. and rainy, but nice




isaacnewtonjuv -> RE: Print This Page Button (10/20/2008 4:14:01)

Hi hhammash,

I would like to know how do I disable the print box from appearing in the browser screen.

In a way using the a 3rd party programming language such as Java or VS 05, rather than just disabling the javascript.

Thanks in advance!




jaybee -> RE: Print This Page Button (10/21/2008 20:32:38)

Hiya, this post is over 6 years old. Can I suggest you go post a full question regarding your problem in the General forum.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.078125