Forum Moderators: open

Message Too Old, No Replies

javascript problem

         

derek123

2:07 pm on May 10, 2005 (gmt 0)

10+ Year Member



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?

thanks~

<html>
<head>
<title></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;
}

function linklist(){
for (var i = 0; i < document.links.length; i++)
document.write(document.links[i]);
}
</script>
</head>
<body>
<a target="_blank" href="javascript:linklist();" onclick="printURL(this.href); return false;"
>print</a><br><br>
<br>
<a href="http://www.google.com.hk">Google.com</a>
</body>
</html>

adni18

12:24 pm on May 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is this code supposed to print the HREF attribute of the link? or the actual content on the page it's linking to?