Microsoft KB Archive/291372

= BUG: Element Behavior Does Not Print or Does Not Appear in Print Preview When You Dynamically Add Content =

Article ID: 291372

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer 5.5

-



This article was previously published under Q291372



SYMPTOMS
When you add dynamic content to an element behavior, this content does not appear in print preview or when you print, although it is displayed correctly in the Internet Explorer window.



CAUSE
When you add dynamic content to an element behavior, Internet Explorer does not persist this dynamic content. When you click Print or Print Preview, Internet Explorer loads and renders the page again. As a result, the dynamic content that you added after the page loaded is not saved and does not appear in print preview or the printed version.



RESOLUTION
To work around this problem, you can use a &quot;persist&quot; property to save the state of the content and ensure that the dynamic content is printed. For more information, see the sample code in the &quot;More Information&quot; section.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
  Create a file named Test1.htc, and paste the following code:  

   



function execute {     var lTest = document.createElement(&quot;P&quot;);

lTest.innerHTML = &quot;This dynamically added text does not appear in print preview&quot;; document.all.div1.innerHTML=&quot;This dynamically added text does not appear in print preview&quot;; document.body.appendChild( lTest ); }

 </HEAD>

<BODY> This static text appears in print preview. </BODY> </HTML> </li> <li> Create a file named Main.htm, and paste the following code: <html XMLNS:TEST>

<?IMPORT NAMESPACE=&quot;TEST&quot; IMPLEMENTATION=&quot;Test1.htc&quot;>

<BODY> <P>Some text from the main page.</P> <CENTER>

<TEST:TEST1 ID=&quot;El&quot;></TEST:TEST1>

</CENTER> <input type=button value=&quot;click me!&quot; onclick=&quot;El.execute;&quot;>

</li> <li>In Internet Explorer, browse to Main.htm.</li> <li>Click click me! to add content inside the behavior. Notice that the text is added to the page.</li> <li>On the File menu, click Print or Print Preview. Notice that none of the dynamically added content appears.</li></ol>

Workaround
To work around this problem, change Test1.htc as follows: <HTML> <HEAD>

 <public:property name=&quot;BodyText&quot; persist=&quot;true&quot; /> <PUBLIC:METHOD name=&quot;execute&quot;/> <PUBLIC:DEFAULTS viewLinkContent /> <public:attach event=&quot;oncontentready&quot; onevent=&quot;setBodyText&quot;/> </PUBLIC:COMPONENT>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;> function setBodyText {       if (BodyText!=null) document.body.innerText = BodyText; }  function execute {     var lTest = document.createElement(&quot;P&quot;); lTest.innerHTML = &quot;This dynamically added text does not appear in print preview&quot;; document.all.div1.innerHTML=&quot;This dynamically added text does not appear in print preview&quot;; document.body.appendChild( lTest ); BodyText = document.body.innerText; }

</SCRIPT> </HEAD> <BODY> This static text appears in print preview. </BODY> </HTML>

<div class="references_section">