...

View Full Version : Why can't Jimmy focus()?



rokosz
09-13-2011, 10:33 PM
I've got an older style frameset (3 frame within). Its a user browse/select set. Top frame is controls, middle is headings & sort control, bottom is the scrollable browse data.

This needs a performance solution since it works fine when the browse data is low volume (or the network is blazing fast).

The prob: Once the set is fully loaded the cursor is placed in a text box in the control frame allowing the user to be able to type a search term without having to click in the textbox.

Problem is the cursor doesn't stick in the bottom frame after _all_ that data loads I tried:


window.parent.MCABrowseControl.document.getElementById('txtQuickFind').focus()
alert("after")

no errors of any kind and for a split second the cursor is visible -- and then is gone (the focus appears to revert to the bottom frames first input (a radio button)

I messed with onreadystatechange but couldn't get my fx to fire when the state became "complete". It only fired once when "loading"

Any methods/properties I can use to solve the issue of _waiting_ for all frames to finish before setting the focus(), and have it stay there?

thanks

Old Pedant
09-14-2011, 12:20 AM
Sure.



<script>
var loaded = 0;
function frameLoaded(whichFrame)
{
loaded |= whichFrame;
if ( loaded == 7 )
{
document.getElementById("someFrameId").document.getElementById('txtQuickFind').focus()
}
}
</script>
<frameset>
...
</frameset>

Then, in the code for *each* frame, do

<body onload="parent.frameLoaded(1);">

<body onload="parent.frameLoaded(2);">

<body onload="parent.frameLoaded(4);">

(That is, use 1,2,4 as the arguments to frameLoaded.)

You see it? As each frame loads, it sets a bit in the frameset's loaded variable.

Only when all 3 have called will the "OR" of the bit values be 7 and only then will you move the focus.

rokosz
09-14-2011, 01:06 PM
Wow, that's so much more elegant than what my brute force idea:

I was starting an effort to load the src parameter for the 2nd, 3rd frames as each of the preceding frames had completed via code.

Thanks! I'd thought there had to be a "frameset" level solution and you clued me in. Jimmy likes to byte.

rokosz
09-14-2011, 09:10 PM
Well, it seems my exuberance has been damped. During installation of the above logic it worked solidly -- as long as there was an alert() (put there for testing) immediately before the .focus() -- or really anywhere in frameLoaded().

Remove the alert() and the .focus will fail anywhere from 10% to 99% of the time (seems to depend on data load -- the 3rd frame can have anywhere from 1 to 100 radio buttons)

so now I'm trying to figure out what processing occurs after all the <body onload> events have fired that would usurp the focus() I just set.

I've been grasping at the following straws (none of which made a diff)
1) ensure caching is on (or off)
2) is self.location.hash=... the culprit
3) is debug mode a culprit (my environment is whack right now re: debug mode). Currently I'm trying to turn it off w/o success (the aspclientdebug=1 cookied will not go away)
4) theres no activex, ajax or coms involved -- straight vbscript,javascript and html.

Anybody out there have an idea of what could be firing after the frames are fully loaded and I've set the focus()?

thanks to all who may help, B

Old Pedant
09-14-2011, 09:49 PM
Well, here's a hacky idea.


<script>
var loaded = 0;
function frameLoaded(whichFrame)
{
loaded |= whichFrame;
if ( loaded == 7 )
{
focusIt();
setTimeout( focusIt, 250 );
}
}
function focusIt( )
{
document.getElementById("someFrameId").document.getElementById('txtQuickFind').focus()
}
</script>

That is, do it once, and then do it again a quarter second later. Should be too fast for humans to worry about.

rokosz
09-15-2011, 01:25 AM
Thank you OPedant - that did the trick. A simple enough hack. Though the curious cat in me still wants to know where the or what the lag is in that page after all the <body>s are loaded...

Old Pedant
09-15-2011, 04:15 AM
Me, too. But without seeing *all* your code, I can't guess.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum