jquery 弹窗 进入网页_使用JQuery打开弹出窗口并打印

A while back I created a lightbox plugin using jQuery that would load a url specified in a link into a lightbox. The code is really simple:

$('.readmore').each(function(i){

$(this).popup();

});

and the link would look like this:

TJ Kirchner

The plugin could also accept arguments for width, height, a different url, and more data to pass through.

The problem I'm facing right now is printing the lightbox. I set it up so that the lightbox has a print button at the top of the box. That link would open up a new window and print that window. This is all being controlled by the lightbox plugin. Here's what that code looks like:

$('.printBtn').bind('click',function() {

var url = options.url + ( ( options.url.indexOf('?') < 0 && options.data != "" ) ? '?' : '&' ) + options.data;

var thePopup = window.open( url, "Member Listing", "menubar=0,location=0,height=700,width=700" );

thePopup.print();

});

The problem is the script doesn't seem to be waiting until the window loads. It wants to print the moment the window appears. As a result, if I click "cancel" to the print dialog box, it'll popup again and again until the window loads. The first time I tried printing I got a blank page. That might be because the window didn't finish load.

I need to find a way to alter the previous code block to wait until the window loads and then print. I feel like there should be an easy way to do this, but I haven't found it yet. Either that, or I need to find a better way to open a popup window and print from the lightbox script in the parent window, without alternating the webpage code in the popup window.

解决方案

You should put the print function in your view-details.php file and call it once the file is loaded by either using

or $(document).ready(function () { window.print(); });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值