...

View Full Version : print preview window



marshallhansen
05-29-2005, 04:39 PM
I would like to create a print preview window that will display only the main content of the page that a person would really want to print. I found a script that didn't do that, but that I was able to adapt, somewhat. It doesn't fully work though and I can't get it any better. Here is what I have...

<html>
<head>
<title></title>
<script LANGUAGE="JavaScript">
function displayHTML(printContent) {
var inf = printContent;
win = window.open("print.htm", 'popup', 'toolbar = no, status = no');
win.document.write(inf);
}
</script>
</head>
<body>
<div id="printarea">Print this stuff.</div>
<a href="javascript:void(0);" onclick="displayHTML(printarea.innerHTML)">Print Preview</a>
</body>
</html>

In mozilla it opens the new window but continues to be thinking about something indefinitly. In Safari the new window opens but there is no content. In IE it seems to work fine. I haven't tested NS yet, nor have I tested any of this on a PC.

Thanks for any help.

vwphillips
05-29-2005, 05:40 PM
<script LANGUAGE="JavaScript">
function displayHTML(printContent) {
var inf = printContent;
win = window.open("print.htm", 'popup', 'toolbar = no, status = no');
win.document.write(inf);
win.document.close(); // new line
}
</script>

marshallhansen
05-29-2005, 05:54 PM
Thank you. That helped the problem in FF. I am still not getting anything in Safari.

vwphillips
05-29-2005, 06:11 PM
cant test with safari

but what is the contet of print.htm

try writing the complete HTML to the popup

win = window.open(' ', 'popup', 'toolbar = no, status = no');

marshallhansen
05-29-2005, 06:26 PM
I did try that and it still didn't work. I also just tested in NS and it didn't work there either. I get a JS error message "printarea is not defined".

print.htm is just an empty document. I created it because the original script that i was working from wasn't calling any file at all and I always got an alert that the file couldn't be found.

vwphillips
05-29-2005, 06:47 PM
dont know how missed this

<a href="javascript:void(0);" onclick="displayHTML(document.getElementById('printarea').innerHTML)">Print Preview</a>

marshallhansen
05-29-2005, 06:50 PM
haha...i just came back to say that i solved the problem in NS with this fix. I layed down to take a nap and it came to me just as i was falling asleep. Unfortunatly it still doesn't work in Safari. Also, the print() doesn't seem to work in IE. I added this....
win.document.write(inf + "<br /><a href='javascript:print()'>print</a>");
and it works except in IE(and Safari of course).

vwphillips
05-29-2005, 07:07 PM
'<span onclick="print();">print</span><br>',

marshallhansen
05-29-2005, 07:13 PM
Thanks for all your help.

glenngv
05-30-2005, 03:49 AM
You can print selected parts of the page by using CSS and without using javascript at all.

http://wsabstract.com/dhtmltutors/cssmedia2.shtml

cfqj
05-25-2011, 08:42 PM
You may try VIEWidget from
http://hexatech.com/viewidget

It is a javascript-programmable report & technical drawing generator and print preview control.
You may use VIEWidget to generate reports or technical drawings,
display the results in a scrolling and zooming viewer on your web page and then print it.
It is a very flexible and productive RAD tool as it lets you freely draw tables or
other objects at arbitrary x-y coordinates.
Below is a simple Hello World example with two print-preview pages generated:

//get length unit
var INCH = control1.getInch();

//create document
control1.startDoc();

control1.drawString(1*INCH, 1*INCH, "Hello World from Page 1");

//...draw other stuff here

//create 2nd page
control1.newPage();
control1.drawString(1*INCH, 1*INCH, "Hello World from Page 2");

//...draw other stuff here

//end document
control1.endDoc();

//preview first page (page index=0)
control1.setCurrentPage(0);
control1.preview();

DanInMa
05-25-2011, 09:04 PM
I did try that and it still didn't work. I also just tested in NS and it didn't work there either. I get a JS error message "printarea is not defined".

print.htm is just an empty document. I created it because the original script that i was working from wasn't calling any file at all and I always got an alert that the file couldn't be found.

I've just gotta ask.. what is NS? please dont say netscape



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum