如何强制浏览器打印广告图像?

时间:2019-05-17 06:41:09

标签: angular

每当我尝试打印带有广告的页面时,它都不会在未启用打印设置的情况下预览页面上的广告。

我已经从浏览器中的打印设置中检查了背景图形,并且该图形正在显示。但是我不需要设置。

这是print-ticket.ts文件

@Component({
    selector: 'app-print-ticket',
    templateUrl: './print-ticket.component.html',
    styleUrls: ['./print-ticket.component.css']
    })
    export class PrintTicketComponent implements OnInit {
    adId = 'prt-ppt-ad-2337188836303-0';
    ngOnInit() {
    }

ngAfterViewInit() {
let tmr = this.serverTimerService.getSrvtimer().subscribe(t=>{
if(!(typeof googletag == 'undefined'
  || typeof googletag.destroySlots != 'function'
  || typeof googletag.defineSlot != 'function'
  || typeof googletag.pubads != 'function'
  || typeof googletag.display != 'function')){
  if(typeof tmr != 'undefined'){
    tmr.unsubscribe();
  }
}
});
this.displayAds('/4213846/PRINT');
}
printTicket() {
var printbutton=document.getElementById("printbuttonid");
printbutton.style.visibility='hidden';
window.print();
printbutton.style.visibility='visible';
}
displayAds(slotT: string){
let tag = window['googletag'];
tag = window['googletag'] || { cmd: [] };
tag.cmd.push( () => {
var mapping = googletag.sizeMapping().    
              build();
googletag.defineSlot(slotT,[[970, 90], [728, 90]],(this.adId))
    .defineSizeMapping(mapping)
    .setCollapseEmptyDiv(true)
    .addService(googletag.pubads());
  googletag.pubads().enableSingleRequest();
  googletag.pubads().collapseEmptyDivs();
  googletag.enableServices();
  googletag.display(this.adId);
});
}
}

Here is html file
<div id="print-section" oncontextmenu="return false" unselectable="on" 
onselectstart="return false;" onmousedown="return false;">
<table width="99%" align="center" cellpadding="0" cellspacing="0" 
border="1" style=" color: black; border-style: solid; border-width: 
1px;">
<tr>
  <td style="padding:2px;">
    <table width="100%" align="center">
                      <tr>
              <td align="center">
                <div [id]='adId' class="iframeBanners">                                           
                </div>
              </td>
            </tr>
              </table>
    </td>
</tr>
</table>
</div>
<table width="98%" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><input id="printbuttonid" type="button" value="Print" 
(click)="printTicket()" /></td>
</tr>
</table>

0 个答案:

没有答案