Cross Browser Way of Taking Block Node Containing Text Into Child Window
My parent window has a button with the containing text "Show Help".
The help text is supposed to be presented in a child window.
The button runs a script that
Retrieves a DOM node of a DIV element containing the help text, with the DIV element CSS property 'display:none;' set
Opens up a child window
Passes the DOM node to a function that has an argument for specifying the content of the body of the child Window
In the past, I would write out the text contained by the DIV element as a Javascript string, containing the HTML markup, and then use document.write() calls in the child window. It is inconvenient to write out long Javascript strings with HTML markup (hard to debug). Also document.write() calls are deprecated by some developers (and don't work for XHTML anyway); DOM methods (appendChild() etc) are preferred.
So I tried using approved methods---which does not include making use of the nonstandard properties outerHTML or innerHTML. I have been testing with FF17, IE9, and Chrome23 in Win7, FF17 in Ubuntu Linux, and IE8 in Win XP. In most cases, IE8 in WinXP is the problem.
I am using .importNode() and only "standardized" methods and properties (ECMA, W3C).
But there are aggravating problems. For example, importNode() works in Firefox, but when I scripted this in FF17 (Win7), it was reporting that childWin.document.body (namely, the body DOM node) was null! If I ran the script in the debugger, the body node was not null! The body node was being referenced in script after the document.close() call, which was itself subsequent to a number of document.write() calls. It was clear that the body node presence was time-dependent...and an onload event seemed to be necessary (why??). But when I write an onload event, it never triggered! These are the aggravations.
And then there is the problem of still writing the code to do the same for IE8 and IE7 earlier versions. Probably I will have to just pass a string made of HTML markup as the body, and use a document.write() call. Not good.
The thing about a non-displayed block element that suddenly appears is that all other elements are sort of pushed around (re-flowed), and that can be unnerving for the user.
One way around it might be:
* the block element (DIV) that is suddenly displayed is done so in a z-layer
* the block element is positioned using CSS (the absolute or fixed property?) and this does NOT cause a re-flowing of the other elements
Will this strategy work? And does it work in IE8 and IE7?
Bookmarks