I got a problem with javascript, that i want to print out hyperlink's contents of the webpage, which without open the webpage. Now, i had writen some codes, which intend to do this task.
But i had meet a problem....so can anyone give me a hand?
This code works:
Code:
<html>
<head>
<title>printing a remote document</title>
<script>
function printURL(sHref) {
if(document.getElementById && document.all && sHref){
if(!self.oPrintElm){
var aHeads = document.getElementsByTagName('HEAD');
if(!aHeads || !aHeads.length)
return false;
if(!self.oPrintElm)
self.oPrintElm = document.createElement('LINK');
self.oPrintElm.rel = 'alternate';
self.oPrintElm.media = 'print';
aHeads[0].appendChild(self.oPrintElm);
}
self.oPrintElm.href = sHref;
self.focus();
self.print();
return true;
}
else return false;
}
</script>
</head>
<body>
<p>
</p>
<h2>The following article discusses what DHTML is, and also the differences in implementation of DHTML between Netscape Communicator and MS Internet Explorer 4. </h2>
<p>What is DHTML? <br>
DHTML(Dynamic HTML) is a technology supported by Netscape Communicator and IE 4 that enables a web document to be dynamic. DHTML is NOT JavaScript, but rather, a generic enhancement to the browser itself that allows elements to be moved around, content to appear and disappear, text to change even after the document has loaded etc. JavaScript (or any other scripting language, for that matter), merely provides the means to access these enhancements. DHTML is not a programming language, but a feature. </p>
<p>What's the difference between DHTML in Communicator, and in Internet Explorer 4.0? <br>
Everything. Communicator and Internet Explorer 4 are currently at very different stages in terms of support for DHTML as recommended by WC3. In short, Communicator is considered vastly behind in its support for true DHTML, while IE 4 is more on track. Its important to realize that both browsers do not yet completely support the DHTML technology as outlined by the WC3. Below lists how Dynamic HTML is implemented in the two browsers: </p>
<p>In Communicator:
<a target="_blank" href="http://www.saltstorm.net/" onclick="printURL(this.href); return false;">print http://www.saltstorm.net</a>
</body>
</html>
But when i try to change it to my local file, this code doesnt:
it just prints the page it is on.
Code:
function printURL(sHref)
{
if(document.getElementById && document.all && sHref)
{
if(!self.oPrintElm)
{
var aHeads = document.getElementsByTagName('HEAD');
if(!aHeads || !aHeads.length)
return false;
if(!self.oPrintElm)
self.oPrintElm = document.createElement('LINK');
self.oPrintElm.rel = 'alternate';
self.oPrintElm.media = 'print';
aHeads[0].appendChild(self.oPrintElm);
}
self.oPrintElm.href = sHref;
self.focus();
self.print();
return true;
}
else return false;
}
<td width="21%" align="center" bgcolor="#006699" onMouseOver="this.bgColor = '#C0C0C0'; this.style.color='#000000'; style.cursor='hand'"
onMouseOut="this.bgColor = '#006699'; this.style.color='#FFFFFF'">
<a target="_blank" href="printBooking.asp?pnrno=<%=pnrno%>"
onclick="printURL(this.href); return false;" style="color:#FFFFFF "
onMouseOver="this.style.color='#000000'" onMouseOut="this.style.color='#ffffff'">View and Print Booking</a>
</td>
www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt