onload and 2 commands...

J

jodleren

Hi all!

I havent used java that much, and lately I updated from M$ java to SUN
(due to my bank).

Before, this worked:
<body onload="SetFocus(); window.focus();">

now, it does not. SetFocus() is included as:
<script language="JavaScript" src="mystuff.js"></script>

Though, this gives an alert:
<body onload="SetFocus(); window.focus();alert('hello')">

What is the difference and the trick here?

BR
Sonnich
 
T

toff

Yeh I ran up against this too. Here's my solution:

<body onload="DoThings();">

function DoThings() { SetFocus(); window.focus() ; }
 
L

-Lost

jodleren said:
Hi all!

I havent used java that much, and lately I updated from M$ java to SUN
(due to my bank).

....which has nothing to do with JavaScript.
Before, this worked:
<body onload="SetFocus(); window.focus();">

now, it does not. SetFocus() is included as:
<script language="JavaScript" src="mystuff.js"></script>

Though, this gives an alert:
<body onload="SetFocus(); window.focus();alert('hello')">

I do not see any error, especially any error that would result from an updated JVM.

You might try:

window.onload = SetFocus;

....inside your mystuff.js.

-Lost
 
L

Lee

jodleren said:
Hi all!

I havent used java that much, and lately I updated from M$ java to SUN
(due to my bank).

Before, this worked:
<body onload="SetFocus(); window.focus();">

now, it does not. SetFocus() is included as:
<script language="JavaScript" src="mystuff.js"></script>

That should be:
<script type="text/javascript" src="mystuff.js"></script>

But this isn't Java, it's Javascript, which is unrelated.
Knowing what "now, it does not" means might help. Do you
see an error message?


--
 
S

Sonnich

Yeh I ran up against this too. Here's my solution:

<body onload="DoThings();">

function DoThings() { SetFocus(); window.focus() ; }

The idea crossed my mind after I wrote this, it did not work.

By some odd reason, the page scroll the item into focus, but it does
not get focus.

The SetFocus() is like this:

function SetFocus()
{
v = document.forms[0];
j=0;
while( (j < v.elements.length) &&
(v.elements[j].type.toLowerCase() == "hidden"))
j++;
if(j < v.elements.length)
{
v.elements[j].focus();
}
}

Set focus, to the first item which is not hidden.

BR
Sonnich
 
S

Sonnich

jodleren said:




That should be:
<script type="text/javascript" src="mystuff.js"></script>

Sorry about the mistake. Will correct.
But this isn't Java, it's Javascript, which is unrelated.
Knowing what "now, it does not" means might help. Do you
see an error message?

I have a file-input, which got a cursor before, now it only scrolls
into focus (but no cursor). It works at work, but not a home. I wonder
whether it tries to focus a hidden input.... maybe I should move them
to the end of my form?
BTW, the other odd thing is, that when I use by bank
(www.amagerbanken.net), then no scripts works afterwards. I have to
restart my computer.

The SetFocus script is added above.

BR
Sonnich
 
R

Robin

Sonnich said:
Sorry about the mistake. Will correct.


I have a file-input, which got a cursor before, now it only scrolls
into focus (but no cursor). It works at work, but not a home. I wonder
whether it tries to focus a hidden input.... maybe I should move them
to the end of my form?
BTW, the other odd thing is, that when I use by bank
(www.amagerbanken.net), then no scripts works afterwards. I have to
restart my computer.

The SetFocus script is added above.

I may be wrong but have you tried putting the "window.focus()" before
the SetFocus call? It's possible that the control is getting focus then
the window is which removes focus from the control.

Robin
 
J

jodleren

Sonnichwrote:




I may be wrong but have you tried putting the "window.focus()" before
the SetFocus call? It's possible that the control is getting focus then
the window is which removes focus from the control.

Yep, that was the trick.

Sorry for the deley.

BR
Sonnich
 

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

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top