Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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