faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

30 of 96 people (31%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How can I repeatedly refresh a frame without either clicking or stealing focus from other frames (location.href clicks, location.reload steals focus)?

Apr 4th, 2008 21:03
ha mo, Ovidiu Crisan, Steve Woods,


Try this (using frames, but you can save the number of the element 
which have focus in cookies), tested with IE.
<HTML><HEAD><TITLE>Keep focus</TITLE></HEAD>
<FRAMESET ROWS="50%,50%" framespacing=0 border=0 frameborder="no">
<FRAME NAME="up" SRC=first.htm>
<FRAME NAME="down" SRC=second.htm>
</FRAMESET></HTML>
second.htm:
-----------
<html>
<head>
<script language=JavaScript>
//keep the id of the element with focus
var f=0;
</script>
</head>
<body>
An empty page!
</body>
first.htm:
----------
<html>
<head>
<META HTTP-EQUIV="REFRESH" CONTENT="5; URL=first.htm">
<script language=JavaScript>
function save(a) {
for(i=0;i<document.forms['frm'].elements.length;i++)
  if(document.forms['frm'].elements[i] == a) top.down.f=i;
}
function load() {
document.forms['frm'].elements[top.down.f].focus()
}
</script>
</head>
<body onload="load()" onunload="save(document.activeElement)">
<form name=frm>
Test1: <input> <br>
<input type=button value="Test2">
</form>
</body>
</html>
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com