Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2008-11-04
Medium Priority
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

Accepted Solution

bluV11t earned 375 total points
ID: 22875556
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" />

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Suggested Courses

577 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