Is this code right?

M

Mark Smith

I have the following function that is supposed to create a popup help
window and fill

it with some text:

function showHelpText(text)
{
win=window.open('/help/
help.html','','width=900,height=400,scrollbars=1');
var e=win.document.getElementById('help');
if(e!=null)
{
e.innerHTML=text;
}
}


The help.html file is as follows:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
</head>
<body style="background-color:#ffffdd;font-family:verdana;font-size:
10pt;">
<div id="help"></div>
</body>
</html>

Calling showHelpText('<p>TEST</p>'); works from IE6+7. But in FF3 the
popup window is

displayed but remains empty...

Here's the kicker: If I put a breakpoint in the function using firebug
and step though

one line at a time it behaves as expected!

Any idea what's going on?

Thanks
 
T

Thomas 'PointedEars' Lahn

Mark said:
I have the following function that is supposed to create a popup help
window and fill

it with some text:

function showHelpText(text)
{
win=window.open('/help/

`win' is declared somewhere, I suppose?
help.html','','width=900,height=400,scrollbars=1');

var e=win.document.getElementById('help');
if(e!=null)
{
e.innerHTML=text;

If `text' stores plain text, you don't want or need the proprietary
`innerHTML'. Use the `nodeValue' or `textContent' properties instead.
}
}


The help.html file is as follows:
<html>
<head>
<title></title>

<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">

Does the Content-Type HTTP header match?
</head>
<body style="background-color:#ffffdd;font-family:verdana;font-size:
10pt;">

<http://www.w3.org/QA/Tips/color>
<http://www.w3.org/TR/CSS2/fonts.html#font-family-prop>
<div id="help"></div>

Looks like an accessibility nightmare altogether.
</body>
</html>

Calling showHelpText('<p>TEST</p>'); works from IE6+7. But in FF3 the

Should be showHelpText(' said:
popup window is

displayed but remains empty...

Here's the kicker: If I put a breakpoint in the function using firebug
and step though

one line at a time it behaves as expected!

Any idea what's going on?

There is a race condition because the document is not necessarily loaded
yet. Debug faster and it will break again. You're having it backwards;
the popup window must notify the opener when its document has loaded
instead. Howewer, this is a textbook example of where _not_ to use
*client-side* scripting.


PointedEars
 
T

The Natural Philosopher

Thomas said:
`win' is declared somewhere, I suppose?


If `text' stores plain text, you don't want or need the proprietary
`innerHTML'. Use the `nodeValue' or `textContent' properties instead.




Does the Content-Type HTTP header match?


<http://www.w3.org/QA/Tips/color>
<http://www.w3.org/TR/CSS2/fonts.html#font-family-prop>


Looks like an accessibility nightmare altogether.




There is a race condition because the document is not necessarily loaded
yet. Debug faster and it will break again. You're having it backwards;
the popup window must notify the opener when its document has loaded
instead. Howewer, this is a textbook example of where _not_ to use
*client-side* scripting.


PointedEars

Indeed. Why not call the popup with a GET or PUT variable set..if a new
window is what you want.

If you juts want a flyout box, code it as part of the main frame, and
simply show it visibility wise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,102
Messages
2,570,645
Members
47,245
Latest member
ShannonEat

Latest Threads

Top