crabine
03-11-2009, 02:59 PM
1) Script Title: DHTML Window widget (v1.1)
2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm
3) Describe problem:
Thanks for providing such a great script, it really works well! However, I have been having difficulty implementing a print button inside the div that is displayed in the dhtmlwindow, which will print just the contents of the div. I do not want to set the print stylesheet for the entire page to print just the contents of the div, since the user should be able to print the rest of the page when they use their regular browser's print function. Most of the page is in ASP.NET 2.0 (VB). My code is as follows:
<div id="hidethis">
<!-- Bunch of page code I want to hide only when the user clicks the print button -->
</div>
<asp:Button ID="btnBudget" runat="Server" Text="Show Budget Info" OnClientClick="budgetwin=dhtmlwindow.open('budgetbox', 'div', 'divBudget', 'Budget Information', 'width=500px,height=250px,left=250px,top=50px,resize=0,scrolling=1'); return false" />
<div id="divBudget">
<div style="padding: 10px;">
<p style="float: right; width: 50px; text-align: right;"><input name="btnPrint" type="button" onclick="PrintFriendly();" value="Print" /></p>
<h1>Title</h1>
<!-- Bunch of page code that I want to print when the user clicks the print button -->
</div>
</div>
<script type="text/javascript">
function PrintFriendly() {
document.getElementById('hidethis').style.display = 'none';
document.getElementById('budgetbox').style.display = "block";
document.getElementById('budgetbox').style.height = "auto";
document.getElementById('budgetbox').style.overflow = "visible";
document.getElementById('divBudget').style.display = "block";
document.getElementById('divBudget').style.height = "auto";
document.getElementById('divBudget').style.overflow = "visible";
window.print();
window.location.reload();
}
</script>
In my screen css file, I hide the div originally: #divBudget { display:none; }
In my print css file, I change the style to show the div: #divBudget { display: block; overflow: visible; height: auto; }
When I use the script above, and click the Print button, it does not print the entire contents of the divBudget div -- It prints only the visible content of the dhtmlwindow (cuts off the rest).
I have also tried using the following javascript function instead:
<script type="text/javascript">
<!--
function printPartOfPage(elementId)
{
var printContent = document.getElementById(elementId);
var windowUrl = 'about:blank';
var windowName = 'Print' + new Date().getTime();
var printWindow = window.open(windowUrl, windowName, 'left=0,top=0,width=0,height=0');
printWindow.document.write(printContent.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
// -->
</script>
If I use <input name="btnPrint" type="button" onclick="printPartOfPage('budgetbox');" value="Print" /> , it prints only the visible content of the dhtmlwindow (cuts off the rest) when the button is clicked.
If I use <input name="btnPrint" type="button" onclick="printPartOfPage('divBudget');" value="Print" /> , it prints a blank page when the button is clicked.
Any help is greatly appreciated.
Thanks!
2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm
3) Describe problem:
Thanks for providing such a great script, it really works well! However, I have been having difficulty implementing a print button inside the div that is displayed in the dhtmlwindow, which will print just the contents of the div. I do not want to set the print stylesheet for the entire page to print just the contents of the div, since the user should be able to print the rest of the page when they use their regular browser's print function. Most of the page is in ASP.NET 2.0 (VB). My code is as follows:
<div id="hidethis">
<!-- Bunch of page code I want to hide only when the user clicks the print button -->
</div>
<asp:Button ID="btnBudget" runat="Server" Text="Show Budget Info" OnClientClick="budgetwin=dhtmlwindow.open('budgetbox', 'div', 'divBudget', 'Budget Information', 'width=500px,height=250px,left=250px,top=50px,resize=0,scrolling=1'); return false" />
<div id="divBudget">
<div style="padding: 10px;">
<p style="float: right; width: 50px; text-align: right;"><input name="btnPrint" type="button" onclick="PrintFriendly();" value="Print" /></p>
<h1>Title</h1>
<!-- Bunch of page code that I want to print when the user clicks the print button -->
</div>
</div>
<script type="text/javascript">
function PrintFriendly() {
document.getElementById('hidethis').style.display = 'none';
document.getElementById('budgetbox').style.display = "block";
document.getElementById('budgetbox').style.height = "auto";
document.getElementById('budgetbox').style.overflow = "visible";
document.getElementById('divBudget').style.display = "block";
document.getElementById('divBudget').style.height = "auto";
document.getElementById('divBudget').style.overflow = "visible";
window.print();
window.location.reload();
}
</script>
In my screen css file, I hide the div originally: #divBudget { display:none; }
In my print css file, I change the style to show the div: #divBudget { display: block; overflow: visible; height: auto; }
When I use the script above, and click the Print button, it does not print the entire contents of the divBudget div -- It prints only the visible content of the dhtmlwindow (cuts off the rest).
I have also tried using the following javascript function instead:
<script type="text/javascript">
<!--
function printPartOfPage(elementId)
{
var printContent = document.getElementById(elementId);
var windowUrl = 'about:blank';
var windowName = 'Print' + new Date().getTime();
var printWindow = window.open(windowUrl, windowName, 'left=0,top=0,width=0,height=0');
printWindow.document.write(printContent.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
// -->
</script>
If I use <input name="btnPrint" type="button" onclick="printPartOfPage('budgetbox');" value="Print" /> , it prints only the visible content of the dhtmlwindow (cuts off the rest) when the button is clicked.
If I use <input name="btnPrint" type="button" onclick="printPartOfPage('divBudget');" value="Print" /> , it prints a blank page when the button is clicked.
Any help is greatly appreciated.
Thanks!