Welcome Guest ( Log In | Register)



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Button To Print Current Web Page
fsoftball
post May 11 2005, 02:56 PM
Post #1


Member [Level 2]
*****

Group: Members
Posts: 78
Joined: 25-April 05
Member No.: 6,158



Hi,

Does anyone know how to create a button that will printo out the current page.

What I want to do is have the user fill out a form (containing name, address, zip, etc). They will then click on a "print" button and it will print out the form data. Any ideas?

Thanks.
Go to the top of the page
 
+Quote Post
cragllo
post May 11 2005, 03:05 PM
Post #2


Privileged Member
*********

Group: Members
Posts: 933
Joined: 24-August 04
Member No.: 892



If you know php, then you could make it so that the form data is 'sent' and displayed on a new page, then have print butten (that may be done with javascript, dunno how tho)

If you need some help, just ask...
Go to the top of the page
 
+Quote Post
fsoftball
post May 11 2005, 03:23 PM
Post #3


Member [Level 2]
*****

Group: Members
Posts: 78
Joined: 25-April 05
Member No.: 6,158



Thanks for the help. I can do the PHP part, I get that. It's the sending it to the printer that I would like to know how to do.
Go to the top of the page
 
+Quote Post
cragllo
post May 11 2005, 04:22 PM
Post #4


Privileged Member
*********

Group: Members
Posts: 933
Joined: 24-August 04
Member No.: 892



A quick search, and I found this:

CODE
<script Language="Javascript">

/*
This script is written by Eric (Webcrawl@usa.net)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

function printit(){  
if (window.print) {
   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>


All tyhe information you need is here, also gives a demo too: http://dynamicdrive.com/dynamicindex9/other1.htm
Go to the top of the page
 
+Quote Post
Inspiron
post May 16 2005, 03:25 PM
Post #5


Trap Grand Marshal Member
***********

Group: Members
Posts: 1,203
Joined: 25-March 05
Member No.: 4,883



cragllo has given a slightly complicated code...
It is broswer sensitive as it test your broswer compatibility before executing the codes...

Here's my version, simple and easy to understand...
This code loads faster as well...

CODE

<html>

<head>
<title>New Page 1</title>
<script language="javascript">
function printpage()
 {
  window.print();
 }
</script>
</head>

<body>

<form>
<input type="button" value="Print" onclick="printpage();">
</form>
</body>

</html>
Go to the top of the page
 
+Quote Post
cragllo
post May 16 2005, 05:23 PM
Post #6


Privileged Member
*********

Group: Members
Posts: 933
Joined: 24-August 04
Member No.: 892



That is simple tongue.gif
And all this talk about printing a page has given me an idea, i will add an options bar to my site smile.gif

You can also use this code instead of the form:
CODE
<a href="" onclick="printpage();">print</a>


This post has been edited by cragllo: May 16 2005, 07:00 PM
Go to the top of the page
 
+Quote Post
Mike
post May 19 2005, 07:57 PM
Post #7


Owner of Sub-Zero
********

Group: Members
Posts: 159
Joined: 17-November 04
Member No.: 2,325



Interesting... All this stuff makes my head explode! dry.gif Anyways, I like the window.print() function the best with JavaScript because it's so simple and you basically cannot forget it. But are you sure that you add the semi-colon (wink.gif at the end of a function in JavaScript?
Go to the top of the page
 
+Quote Post
spacemonkey
post May 25 2005, 05:54 PM
Post #8


Member [Level 2]
*****

Group: Members
Posts: 76
Joined: 2-March 05
From: USA
Member No.: 4,110



You could even omit the Javascript with the function by using the command right from the button:
CODE
<input type="button" value="Print Page!" onclick="window.print()" />
Go to the top of the page
 
+Quote Post
monkeys-r-orange
post Jun 13 2005, 12:58 PM
Post #9


Newbie [Level 1]
*

Group: Members
Posts: 20
Joined: 12-June 05
Member No.: 8,158



Thank you for helping so many of us.

I have always woundered how to allow users to print a page of my website.

thanks again.

happy.gif
<