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.
↑ Back to the top
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.
↑ Back to the top
To work around this problem, you can use a "persist" 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 "More Information" section.
↑ Back to the top
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
↑ Back to the top
Steps to Reproduce Behavior
1. | Create a file named Test1.htc, and paste the following code:
<HTML>
<HEAD>
<PUBLIC:COMPONENT tagName="TEST1" literalContent="false">
<PUBLIC:METHOD name="execute"/>
<PUBLIC:DEFAULTS viewLinkContent />
</PUBLIC:COMPONENT>
<SCRIPT LANGUAGE="JavaScript">
function execute()
{
var lTest = document.createElement("P");
lTest.innerHTML = "This dynamically added text does not appear in print preview";
document.all.div1.innerHTML="This dynamically added text does not
appear in print preview";
document.body.appendChild( lTest );
}
</SCRIPT>
</HEAD>
<BODY>
This static text appears in print preview.</br>
<div id=div1 name=div1></div>
</BODY>
</HTML>
|
2. | Create a file named Main.htm, and paste the following code:
<html XMLNS:TEST>
<head>
<?IMPORT NAMESPACE="TEST" IMPLEMENTATION="Test1.htc">
</head>
<BODY>
<P>Some text from the main page.</P>
<CENTER>
<TEST:TEST1 ID="El"></TEST:TEST1>
</CENTER>
<input type=button value="click me!" onclick="El.execute();">
</body>
</html>
|
3. | In Internet Explorer, browse to Main.htm. |
4. | Click click me! to add content inside the behavior. Notice that the text is added to the page. |
5. | On the File menu, click Print or Print Preview. Notice that none of the dynamically added content appears. |
Workaround
To work around this problem, change Test1.htc as follows:
<HTML>
<HEAD>
<PUBLIC:COMPONENT tagName="TEST1" literalContent="false">
<public:property name="BodyText" persist="true" />
<PUBLIC:METHOD name="execute"/>
<PUBLIC:DEFAULTS viewLinkContent />
<public:attach event="oncontentready" onevent="setBodyText()"/>
</PUBLIC:COMPONENT>
<SCRIPT LANGUAGE="JavaScript">
function setBodyText()
{
if (BodyText!=null)
document.body.innerText = BodyText;
}
function execute()
{
var lTest = document.createElement("P");
lTest.innerHTML = "This dynamically added text does not appear in print preview";
document.all.div1.innerHTML="This dynamically added text does not appear in print preview";
document.body.appendChild( lTest );
BodyText = document.body.innerText;
}
</SCRIPT>
</HEAD>
<BODY>
This static text appears in print preview.</br>
<div id=div1 name=div1></div>
</BODY>
</HTML>
↑ Back to the top
For more information about element behaviors, see the following Microsoft Web site:
For additional information, click the article numbers below
to view the articles in the Microsoft Knowledge Base:
259016 PRB: Detach Method of Binary Behavior Is Never Called
271239 SAMPLE: DLLList.exe Lists Details with Binary Element Behavior
256228 HOWTO: Make Script Element Behaviors Participate in Forms Submission
257353 BUG: Cannot Access FRAMES Collection of Element Behavior
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
↑ Back to the top