Jump to content
xisto Community
fsoftball

Button To Print Current Web Page

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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>

Share this post


Link to post
Share on other sites

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 (see edit history)

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

I am not a javascript expert, (far from it, in fact), but simply wanted to suggest that using javascript to 'select' a printer may not be an option, due to the controls about whether the Browser (javascript) can make certain choices for the User. If javascript can select the default printer, it could also de-select the printer and javascript is not allowed to do various things such as this. it is a designed feature to limit the ability of the web softwares to 'control' your web viewing.

Share this post


Link to post
Share on other sites

I a simple link with this code is enought to print the content of the page

<a href="java script:print();">Print this Page</a>

This will work in IE, FF & Opera but not in safari

Share this post


Link to post
Share on other sites

Of course you couldn't print without displaying the box first. If javascript had that kind of power could you imagine the abuse websites could do? Print out 40 pages of pure black while your surfing the net and you wouldn't even know until you hear the printer going.

This will work in IE, FF & Opera but not in safari

It works fine in safari.

Share this post


Link to post
Share on other sites

HTML code to print web page

Button To Print Current Web Page

 

Replying to spacemonkey

 

Dear Spacemonkey,

 

Back in May of 2005, you responded to a question of what HTML code is necessary to print a web page that included "fill in form" features. I was impressed with how simple your coding was. You suggested: <input type="button" value="Print Page!" onclick="window.Print()" />

 

It works like a charm. I have another question for you now. Is there a simple code that sends the selected web page to someone when they click a "Submit" button. I need to know how to include an email address with that feature.

 

Thanks in advance for any help you can offer.

Tom T

 

-question by Tom T

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.