The code works fine in Firefox and Chrome, but won't run in IE8. Here it is:
Code: Select all
function addHeading() {
// New snippet for page heading.
pageTitleTableCell = document.createElement("TD");
h1Title = document.createElement("H1");
pageTitleTableCell.appendChild(h1Title);
h1Title.setAttribute("style", "font-family : Calibri,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size : 21px; font-weight : normal; color : #FFFFFF; margin-left : 140px; margin-top : 20px");
h1Title.appendChild(document.createTextNode(window.top.document.title));
// Find the logo image, and insert the heading snippet after it.
toolbar = window.top.frames[0].document; // Find the toolbar frame.
logoTableCell = toolbar.getElementById("logoIcon"); // Find the table cell that contains the logo.
test = toolbar.getElementById("ToolbarButtons"); // Test with a higher-level object: see explanation below.
alert(test.id); // Check if the test worked. (It does - see below.)
alert(logoTableCell.id); // Check if the logo table cell has been found and assigned to logoTableCell
// (works in FF and Chrome; IE8's debugger says "Object required").
logoTableCell.parentNode.appendChild(pageTitleTableCell); // Insert the heading snippet created earlier.
// (Works in FF and Chrome, not in IE8.)
}
window.onload = addHeading();As you can see, I inserted a temporary alert box to see what's going on: alert(logoTableCell.id); In FF and Chrome, the alert box correctly displays the id attribute of the table cell. In IE, the alert box does not appear, and the script stops running. When I look in IE's debugger, I see the error message "Object required". (I've tried stepping through the script in IE's debugger but the step buttons are greyed out
When I looked at the toolbar frame's source in IE, I noticed that the toolbar buttons are not present in the page when it loads. Evidently they are loaded by MadCap's JavaScript subsequently:
Code: Select all
<body>
<table style="height: 28px;">
<tr>
<td id="ToolbarButtons">
<!-- Toolbar buttons and logo are inserted here -->
</td>
</tr>
</table>
</body>To test this, I added an assignment for the table cell that contains the entire toolbar, called ToolbarButtons; this cell is in the initial HTML as soon as the frame loads:
test = toolbar.getElementById("ToolbarButtons");
Sure enough, this assignment works: the temporary alert box I added to check it displays the id of the table cell as expected.
Has anyone else come across this issue? How do I get IE to run my script over the final toolbar, rather than the initial empty one? And why does it behave differently from other browsers?
Thanks for any advice - this is doing my head in