FAQ server wrote:
-----------------------------------------------------------------------
FAQ Topic - I have window.status="Moomin"; why doesn't the statusbar change?
-----------------------------------------------------------------------
When changing the status in an event (e.g. onmouseover) you
should return true from the event.
>From the *event handler itself* and not from a function called by this
handler. The most often mistake was:
<html>
<head>
<title>window.status demo</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function setStatus(message) {
window.status = message;
return true;
}
</script>
</head>
<body>
<p>
<a href="noscript.html"
onMouseOver="setStatus('a JavaScript call');"
onMouseOut="setStatus(window.defaultStatus);"
onClick="window.alert('a JavaScript call'); return false;">Wrong
status set demo</a>
</p>
</body>
</html>
That seems that setStatus return true as requested yet status change
doesn't work. This is because out intrinsic handler is in fact an
anonymous function calling setStatus(), so we have:
function anonymous() {
setStatus('a JavaScript call');
}
and respectively we do not return any true from that anonymous
function. The proper way is:
<html>
<head>
<title>window.status demo</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function setStatus(message) {
window.status = message;
return true;
}
</script>
</head>
<body>
<p>
<a href="noscript.html"
onMouseOver="return setStatus('a JavaScript call');"
onMouseOut="return setStatus(window.defaultStatus);"
onClick="window.alert('a JavaScript call'); return false;">Right
status set demo</a>
</p>
</body>
</html>
Also a number of browsers
require a short delay before setting the status to overcome their
default behaviour with the statusbar.
onevent="setTimeout('window.status=\'Moomin\'',15) ;"
Besides it is not a working sample whatsoever (no true return value):
which browsers require such delay?
Some browsers may be configured to disallow scripts from setting
the status.
Full ACK, and more and more of them: as the status message change is
one of common annoyances and a potential security risk (links fraud).
Yet if we give a sample of use, let's make it at least properly working
(where allowed).
All possible usage methods (on UA's where not blocked):
<html>
<head>
<title>window.status demo</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function setStatus(message) {
window.status = message;
return true;
}
function init() {
var p = document.getElementById('p04');
p.onmouseover = function() {
window.status = 'a JavaScript call';
return true;
}
p.onmouseout = function() {
window.status = window.defaultStatus;
return true;
}
p.onclick = function() {
window.alert('a JavaScript call');
return false;
}
}
window.onload = init;
</script>
</head>
<body>
<p>
<a href="noscript.html"
onMouseOver="window.status = 'a JavaScript call'; return true;"
onMouseOut="window.status = window.defaultStatus; return true;"
onClick="window.alert('a JavaScript call'); return false;">Intrinsic
handler demo</a>
</p>
<p>
<a href="noscript.html"
onMouseOver="return setStatus('a JavaScript call');"
onMouseOut="return setStatus(window.defaultStatus);"
onClick="window.alert('a JavaScript call'); return false;">Function
call demo</a>
</p>
<p>
<a href="noscript.html"
onMouseOver="setStatus('a JavaScript call');"
onMouseOut="setStatus(window.defaultStatus);"
onClick="window.alert('a JavaScript call'); return false;">Wrong
function call demo</a>
</p>
<p id="p04">Programmatically attached handler demo</p>
</body>
</html>