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="javas cript" type="text/javascript"$
(document).read y(function(){ $('.mylink').cl ick(function()
{ $.jPrintArea('# tabularData') }); });
jQuery.jPrintAr ea=function(el) {
alert("hello");
var iframe=document .createElement( 'IFRAME');var doc=null;
$(iframe).attr( 'style','positi on:absolute;wid th:0px;height:
0px;left:-500px;top:-500px;');
document.body.a ppendChild(ifra me);
doc=iframe.cont entWindow.docum ent;
var links=window.do cument.getEleme ntsByTagName('l ink');
for(var i=0;i<links.len gth;i++)
if(links[i].rel.toLowerCas e()=='styleshee t')doc.write('< link
type="text/css" rel="stylesheet " href="'+links[i].href+'"></link>');
doc.write('<div class="'+$(el). attr("class")+' ">'+$(el).html( )+'</
div>');
doc.close();
iframe.contentW indow.focus();
iframe.contentW indow.print();a lert('Printing. ..');//
wait(1);documen t.body.removeCh ild(iframe);}
</script>
</head>
<body>
<div id="tabularData ">
....
</div>
<a href="#" class="mylink" name="mylink">P rint 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="javas cript" type="text/javascript"$
(document).read y(function(){ $('.mylink').cl ick(function()
{ $.jPrintArea('# tabularData') }); });
jQuery.jPrintAr ea=function(el) {
alert("hello");
var iframe=document .createElement( 'IFRAME');var doc=null;
$(iframe).attr( 'style','positi on:absolute;wid th:0px;height:
0px;left:-500px;top:-500px;');
document.body.a ppendChild(ifra me);
doc=iframe.cont entWindow.docum ent;
var links=window.do cument.getEleme ntsByTagName('l ink');
for(var i=0;i<links.len gth;i++)
if(links[i].rel.toLowerCas e()=='styleshee t')doc.write('< link
type="text/css" rel="stylesheet " href="'+links[i].href+'"></link>');
doc.write('<div class="'+$(el). attr("class")+' ">'+$(el).html( )+'</
div>');
doc.close();
iframe.contentW indow.focus();
iframe.contentW indow.print();a lert('Printing. ..');//
wait(1);documen t.body.removeCh ild(iframe);}
</script>
</head>
<body>
<div id="tabularData ">
....
</div>
<a href="#" class="mylink" name="mylink">P rint this Table</a>
</body>
</html>
Comment