• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Strange JavaScript error...

JonTheBaller

Golden Member
I have a javascript function to open a window with the document as a frameset, and display a URL in a given frame. I am having a weird error.


Here is the code:


function openAnchor( anchor )
{
var helpWindow = window.open( "frames.jsp", "Frames", config="..." );
var displayURL = "page.htm#" + anchor;
helpWindow.display.location.href = displayURL;
}


I get the error helpWindow is not defined.



However, if I add an alert:


function openAnchor( anchor )
{
var helpWindow = window.open( "frames.jsp", "Frames", config="..." );
alert( "abc" );
var displayURL = "page.htm#" + anchor;
helpWindow.display.location.href = displayURL;
}


The code works - the URL is displayed in the appropriate frame (after I hit OK on the alert).
 
i am making a blind guess here...
when your script executes and it reaches
helpWindow.display.location.href = displayURL;

when you have the alert(), the browser would receive a delay because of the alert box. and by the time you OK-ed the alert box, the new window would've been created already and the page will load correctly.

however, when you don't have the alert() stuffs, the call to that line might have been too soon. i.e.: the browser didn't have enough time to create helpWindow before you call it.

try adding a loop or a sleep() (i can't remember if javascript has sleep() function) function before calling the last line.

if i'm wrong, just disregard this ... it's too early for me to be thinking ....
 
Back
Top