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?
<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”>Google.com</a>
<br>
<a href=”http://www.yahoo.com”>Yahoo.com</a>
</body>
</html>