[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 634
  • Last Modified:

Print DOM object changes?

Hi all.

Is there an easy way to print the changes made to the dom? For instance, if i have a blank html page with a div tag and via javascript i manipulate that div tag and place an image within the div using createElement('img'), etc.  Is there any way to print it?  Currently, when I do a print preview, the page I'm viewing is completely blank.

  • 2
1 Solution
this works both on IE and FF

<title>Author: Third Santor</title>
function test(){
  var d = document.getElementById("mydiv");
  var i = document.createElement("IMG");
  i.src = "winxp.gif";
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" onload="test();">
<div id="mydiv"></div>
sapientconceptionsAuthor Commented:
Thanks Third. You are correct in that it works in both browsers.  My tests however weren't for the img tag, but instead for background-image.  I was able to get the background image to appear for pritning in IE by turning on the option, however in firefox (even with the option enabled) the background doesn't appear.  

Any advice on that?
sapientconceptionsAuthor Commented:
Third, I figured out my problem.  In my stylesheet for the div, i had z-index set to -1.  Firefox ignores the layer if defined with -1, so removing that, the printing option works as expected. Thanks for your assistance.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now