Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Print this page with target="_self"


  • Please log in to reply

#1
promoter

promoter

    Member

  • Member
  • PipPip
  • 31 posts
I copied some free javascript to add a "Print this Page" link on a webpage. It works but it opens a new window as well. What code can I put to stop another window from opening? Here is the code I have in my head tag:

<script language="JavaScript">
var gAutoPrint = true; // Tells whether to automatically call the print function

function printSpecial()
{
if (document.getElementById != null)
{
var html = '<HTML>\n<HEAD>\n';

if (document.getElementsByTagName != null)
{
var headTags = document.getElementsByTagName("head");
if (headTags.length > 0)
html += headTags[0].innerHTML;
}

html += '\n</HE>\n<BODY>\n';

var printReadyElem = document.getElementById("printReady");

if (printReadyElem != null)
{
html += printReadyElem.innerHTML;
}
else
{
alert("Could not find the printReady function");
return;
}

html += '\n</BO>\n</HT>';

var printWin = window.open("","printSpecial");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint)
printWin.print();
}
else
{
alert("The printReady feature is only available if you are using a browser. Please update your browser.");
}
}

</script>

And here is what I have in the body tag:

<div id="printReady"> 
<table align="center" width="800">
<tr>
  <td colspan="2"><p><a href="java script:void(printSpecial())" target="_self">Print Map</a> </p></td>
  <td colspan="2" valign="top"> </td>
</tr>
</table></div> //There is more in this div but I didn't feel it was necessary to show

Here is the link: http://www.fifthstre...ces.com/map.htm. It is not a live page, so pay no attention to the crappy map!

Thanks so much! (And thanks for always helping me!)

Edited by promoter, 27 June 2007 - 11:52 AM.

  • 0

Advertisements


#2
BirdieUK

BirdieUK

    Member

  • Member
  • PipPip
  • 33 posts
var printWin = window.open("","printSpecial");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint)
printWin.print();
}
else
{
alert("The printReady feature is only available if you are using a browser. Please update your browser.");
}
The printwin variable is used to open a window where the info inside is then printed by .print. So you'd have to think of an alternative method to print it, such as the page itself?
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP