css - Opening inline div in new window with javascript -


i using previous question in me "open-in-new-window" javascript function:

copy div , style new window

so goal open inline div in new window , able print new window (the div want open in new window coupon).

i've accomplished styling div (to coupon) , set javascript div indeed open in new window, but

1) ...i can't style sheet link new window,

2) ...and, can't new window print (instead nothing happens when click print new window - when close new window, print dialogue box appears.

here code i'm using far, appreciated:

$('#printcoupon').bind('click', function () {     var printcontents = new $("#coupon").clone();                var mywindow = window.open("", "popup", "width=600,height=380,scrollbars=yes,resizable=yes," + "toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0");     var doc = mywindow.document;     doc.open(); $(printcontents).find("#printcoupon").remove();     doc.write("<!doctype html public \"-//w3c//dtd xhtml 1.0 transitional//en\" \"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd\">");     doc.write("<html>");     doc.write("<head>");     doc.write("<link href='http://[link-to-css]/css/coupon.css' rel='stylesheet' type='text/css' />"); // css file comes here.     doc.write("</head>");     doc.write("<body>");     doc.write($(printcontents).html());     doc.write("</body>");     doc.write("</html>"); }); 

and html:

<div id="couponwrap">     <div id="coupon">         <h3>coupon title</h3>         <p>present coupon , receive $10 off labor on first service visit , 2% loyalty points on next visit.</p>     </div>         <a href="javascript:;" id="printcoupon">click print coupon.</a> </div> 

thank you, cindy

as far writing, try following (removed doc.open() , removed popup argument):

$('#printcoupon').bind('click', function () {     var printcontents = new $("#coupon").clone();                var mywindow = window.open("", "", "width=600,height=380,scrollbars=yes,resizable=yes," + "toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0");     var doc = mywindow.document; $(printcontents).find("#printcoupon").remove();     doc.write("<!doctype html public \"-//w3c//dtd xhtml 1.0 transitional//en\" \"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd\">");     doc.write("<html>");     doc.write("<head>");     doc.write("<link href='http://[link-to-css]/css/coupon.css' rel='stylesheet' type='text/css' />"); // css file comes here.     doc.write("</head>");     doc.write("<body>");     doc.write($(printcontents).html());     doc.write("</body>");     doc.write("</html>"); }); 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -