...

View Full Version : JavaScript print function



dereuckn
07-04-2006, 12:27 PM
I am relatively new to programming and trying to get a bit of script someone else wrote to work but only part of the script seem to be working and I don't know enough about JavaScript to understand all of the script. Basically what I am trying to do is write a script for a printer friendly page. We have rather elaborate page layouts that do not print very well so I am trying to create a script that only prints out certain elements of a page i.e page title, content, date, url and content heading.

Please can anyone help?

This is the code that we link to the web page template

//This script is used in all templates for the print function
function openTemplatePrintBox() { /* this function opens up a printer friendly version of the page */

pWin = window.open("about:blank", "printWindow", "height=530,width=740,location=no,menubar=yes,status=no,toolbar=no,resizable=yes,scrollbars=yes");
var t = document.forms.fields.PageTitle.value; //this is the same reference used by feedback - it was forms[1].PageTitle
var d = pWin.document;
d.open("text/html");
d.writeln("<html><head><title>" + t + "</title>")
d.writeln("<link href=\"/__802569F4005E3A85.nsf/vWeb/flNDRK6QTEE8/$File/PortalStyleSheetv4.css\" rel=\"stylesheet\" type=\"text/css\"></head>\n");
d.writeln("<body bgcolor=\"white\" text=\"black\" onload=\"javascript:window.print()\">");
d.writeln(document.all["divPageTitle"].innerHTML);
d.writeln(document.all["divContentBox"].innerHTML);
d.writeln("</body></html>\n");
d.close();

}

This is the code on the template page relating to the ubove script. Also I have to CSS divs called "divPageTitle" and "divContentBox".

<A href="Javascript:openTemplatePrintBox()">Print</a>
<form name=fields>
<input type="hidden" name="DocOwner" value="amanet@baa.com">
<input type="hidden" name="PageTitle" value=" - ">
<input type="hidden" name="SiteName" value="AMA-net">
</form>

martin_narg
07-04-2006, 04:53 PM
I would be inclined to look into print style sheets: http://www.alistapart.com/stories/goingtoprint/

It should save you considerable heartache!

Hope this helps

m_n

jetbrains
07-09-2006, 03:42 AM
See this Javascript print tutorial.

http://www.developerzone.biz/index.php?option=com_content&task=view&id=150&Itemid=45

Hope this helps



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum