We javascript-ers all know how to set focus to a control:
coltrol.focus();
But how to know if a control is focused or not using javascript?
Three answers:
Dave H
2007-08-03 01:11:59 UTC
Use the onfocus and onblur events for the control.
If javascript is not enabled, there is no javascript code that will indicate this because it is not enabled.
You could have a initial page that tests for javascript. This page would through javascript re-direct to the appropriate page. If the re-direct did not happen, the page would state that javascript needs to be enabled to view this page.
E.M.Bed
2007-08-03 10:52:24 UTC
There is a way to detect if javascript is enabled using javascript:
You do not have Javascript enabled
HTML
The wrapper div wraps around the HTML of your page body.
Aside from this, I agree with onfocus and onblur even though not all browsers support them.
if(window.focus) and if(window.blur) tests if they are supported.
Kent Brewster
2007-08-03 16:20:17 UTC
Like so:
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.