Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Button To Print Current Web Page


22 replies to this topic

#1 fsoftball

    Member [Level 2]

  • Kontributors
  • PipPipPipPipPip
  • 78 posts

Posted 11 May 2005 - 02:56 PM

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.

#2 cragllo

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 933 posts

Posted 11 May 2005 - 03:05 PM

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...

#3 fsoftball

    Member [Level 2]

  • Kontributors
  • PipPipPipPipPip
  • 78 posts

Posted 11 May 2005 - 03:23 PM

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.

#4 cragllo

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 933 posts

Posted 11 May 2005 - 04:22 PM

A quick search, and I found this:

<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....dex9/other1.htm

#5 Inspiron

    Trap Grand Marshal Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,204 posts

Posted 16 May 2005 - 03:25 PM

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...

<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>


#6 cragllo

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 933 posts

Posted 16 May 2005 - 05:23 PM

That is simple :(
And all this talk about printing a page has given me an idea, i will add an options bar to my site :lol:

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

Edited by cragllo, 16 May 2005 - 07:00 PM.


#7 Mike

    Owner of Sub-Zero

  • Kontributors
  • PipPipPipPipPipPipPipPip
  • 159 posts

Posted 19 May 2005 - 07:57 PM

Interesting... All this stuff makes my head explode! :lol: 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 (:( at the end of a function in JavaScript?

#8 spacemonkey

    Member [Level 2]

  • Kontributors
  • PipPipPipPipPip
  • 76 posts
  • Location:USA

Posted 25 May 2005 - 05:54 PM

You could even omit the Javascript with the function by using the command right from the button:
<input type="button" value="Print Page!" onclick="window.print()" />


#9 monkeys-r-orange

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 20 posts
  • Interests:I like model rockets, video games(PS2), surfing the web, drawing, and sleeping.

Posted 13 June 2005 - 12:58 PM

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.

:P

#10 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 06 February 2008 - 05:46 AM

how to print without asking the dialogue box.
Button To Print Current Web Page

I am using the window.Print(); option for printing the current page .

Here it is asking me which printer to print ect...

In a dialogue box.
I want to select the default printer of that machine and print it automatically.

-question by honey




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users