How to print background image with javascript window.print()

Posted on 2008-11-04
Last Modified: 2012-05-05
I have a aspx page that calls window.print() from an imagebutton to print the current page. It doesn't print the background image of the companys logo, because the javascript apparently strips out images and background images. Know I know that you normally need to change a setting in IE under Tools -> allow printing background images, but I don't wan't to ask my users to do that.
Is there some kind of workaround to get the company logo on the page that's printed?
Question by:ThomasCookScandinavia
    1 Comment
    LVL 7

    Accepted Solution

    You could do this with CSS.

    What you do is put your logo in a normal <asp:image tag and set its cssclass to somthing like "printable_logo"

    In your css file you then specify that the class "printable_logo" is not displayed:

    .printable_logo{display: hidden;}

    In the link tag for the css -file you add media="all" like this:
       <link href="your_style_sheet.css" rel="stylesheet" type="text/css" media="all" />

    Then, just below the link tag for the css - file you add this:

    <style type="text/css" media="print">
       .printable_logo{display: inline}

    You could also have entire stylesheets for each:

       <link href="your_style_sheet.css" rel="stylesheet" type="text/css" media="all" />
       <link href="your_style_sheet_print.css" rel="stylesheet" type="text/css" media="print" />

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Live - One-on-One JavaScript Help from Top Experts

    Solve your toughest problems, fast.
    JavaScript experts are online now and ready to help you.

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now