fsoftball 0 Report post Posted May 11, 2005 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
cragllo 0 Report post Posted May 11, 2005 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
fsoftball 0 Report post Posted May 11, 2005 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. Share this post Link to post Share on other sites
cragllo 0 Report post Posted May 11, 2005 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
Inspiron 0 Report post Posted May 16, 2005 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
cragllo 0 Report post Posted May 16, 2005 (edited) 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 You can also use this code instead of the form: <a href="" onclick="printpage();">print</a> Edited May 16, 2005 by cragllo (see edit history) Share this post Link to post Share on other sites
Mike 0 Report post Posted May 19, 2005 Interesting... All this stuff makes my head explode! 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
spacemonkey 0 Report post Posted May 25, 2005 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()" /> Share this post Link to post Share on other sites
monkeys-r-orange 0 Report post Posted June 13, 2005 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. Share this post Link to post Share on other sites
iGuest 3 Report post Posted February 6, 2008 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
jlhaslip 4 Report post Posted February 6, 2008 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
delivi 0 Report post Posted February 6, 2008 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
galexcd 0 Report post Posted February 6, 2008 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 safariIt works fine in safari. Share this post Link to post Share on other sites
tefanclub 0 Report post Posted March 7, 2008 thanks Share this post Link to post Share on other sites
iGuest 3 Report post Posted September 1, 2008 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