S
souporpower
Hi All
I am trying to print some HTML using JQUERY. I am posting the code. I
don't
see the alert. It seems as though the function is not registered when
the
document is loaded. Can someone please clarify what I am doing wrong?
BTW, I am using IE8 and Chrome to test. Sorry I can't place the code
in a web site.
Thanks for your help
<html>
<head>
<script type="text/javascript" src="../../resources/js/
jquery-1.2.6.js"> </script>
<script language="javascript" type="text/javascript"> $
(document).ready(function(){ $('.mylink').click(function()
{ $.jPrintArea('#tabularData') }); });
jQuery.jPrintArea=function(el){
alert("hello");
var iframe=document.createElement('IFRAME');var doc=null;
$(iframe).attr('style','position:absolute;width:0px;height:
0px;left:-500px;top:-500px;');
document.body.appendChild(iframe);
doc=iframe.contentWindow.document;
var links=window.document.getElementsByTagName('link');
for(var i=0;i<links.length;i++)
if(links.rel.toLowerCase()=='stylesheet')doc.write('<link
type="text/css" rel="stylesheet" href="'+links.href+'"></link>');
doc.write('<div class="'+$(el).attr("class")+'">'+$(el).html()+'</
div>');
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();alert('Printing...');//
wait(1);document.body.removeChild(iframe);}
</script>
</head>
<body>
<div id="tabularData">
....
</div>
<a href="#" class="mylink" name="mylink">Print this Table</a>
</body>
</html>
I am trying to print some HTML using JQUERY. I am posting the code. I
don't
see the alert. It seems as though the function is not registered when
the
document is loaded. Can someone please clarify what I am doing wrong?
BTW, I am using IE8 and Chrome to test. Sorry I can't place the code
in a web site.
Thanks for your help
<html>
<head>
<script type="text/javascript" src="../../resources/js/
jquery-1.2.6.js"> </script>
<script language="javascript" type="text/javascript"> $
(document).ready(function(){ $('.mylink').click(function()
{ $.jPrintArea('#tabularData') }); });
jQuery.jPrintArea=function(el){
alert("hello");
var iframe=document.createElement('IFRAME');var doc=null;
$(iframe).attr('style','position:absolute;width:0px;height:
0px;left:-500px;top:-500px;');
document.body.appendChild(iframe);
doc=iframe.contentWindow.document;
var links=window.document.getElementsByTagName('link');
for(var i=0;i<links.length;i++)
if(links.rel.toLowerCase()=='stylesheet')doc.write('<link
type="text/css" rel="stylesheet" href="'+links.href+'"></link>');
doc.write('<div class="'+$(el).attr("class")+'">'+$(el).html()+'</
div>');
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();alert('Printing...');//
wait(1);document.body.removeChild(iframe);}
</script>
</head>
<body>
<div id="tabularData">
....
</div>
<a href="#" class="mylink" name="mylink">Print this Table</a>
</body>
</html>