开发者

Is there a way to print the Contents of a Specific DIV

I have a P开发者_C百科ape width different DIVs and a PRINT link. I want that if the user clicks on a Print link should a specific DIV be printed not the whole page.


I think you can use CSS, like so:

@media print {
  body * {
    display:none;
  }

  #divToPrint {
    display:block;
  }
}

but I don't think this is supported on all browsers. The alternative would be to open the contents of the DIV in a new window, and then print that window.


Use print media stylesheets to set everything else to display: none (you'll need to construct your markup in such a way that nothing you want to print is a descendent of something you do want to print).

Toggle class names on the div elements to select which ones get printed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜