开发者

how to make a pop-out for printing?

开发者 https://www.devze.com 2023-01-08 10:24 出处:网络
Need to make a function that would open a popout with a div inheriting innerhtml from another di开发者_Go百科v on that page.

Need to make a function that would open a popout with a div inheriting innerhtml from another di开发者_Go百科v on that page.

For example, the initial div might have some sort of a table, therefor when the user presses the print button, this div would open in a new popout. :)

EDIT:

Thanks, got it working!

function opentrint(  ) { 

var $toprint = $('#divToPrint').html();
myWin=window.open('','myWin','menubar,scrollbars,left=30px,top=40px,height=400px,width=600px');
myWin.document.write($toprint); 

}


use var printwindow = window.open('file', 'uniqueid', 'width=400, height=300');

to open a new window. That script that you're calling in file should be able to access the opener window by var div = window.opener.getElementById('divid');

It should be possible to wrap window.opener in a jQuery object. You might even need to use $(window.opener).contents().find('#divid');.


you might want to check out this plugin: http://plugins.jquery.com/project/jqPrint

it allows you to print specific parts of a page. then you don't have to deal with pop-outs and such.


The best way to go about this is to first make sure you don't get what you want from print stylesheet before using a plugin.

First try to alter the page CSS using an alternative stylesheet that has media="print" that way for example you can make the page black and white or take some images you dont need the print sheet off

0

精彩评论

暂无评论...
验证码 换一张
取 消