473,804 Members | 4,288 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Update a Div Only When Window Receives Focus

I have an AJAX enabled page which contains a list of records out of a
database which are loaded into a div via an AJAX call.

If the user switches to another window, and comes back to this open
window later on, I want the list of records to be udpated when the
window is back in front

a simple onFocus doesn't work, as what happens is that if a button is
clicked on the window it causes the onfocus to fire as well

I've tried (unsuccessfully ) to block onfocus events from reaching the
window object from other objects (like buttons or images), but I can't
seem to get this to work

I just want the div to reload if the window gains focus!!!!!

there is surely something simple I am missing????

Sep 11 '06 #1
8 2264
VK
zacware wrote:
If the user switches to another window, and comes back to this open
window later on, I want the list of records to be udpated when the
window is back in front
Then you need to monitor window.onfocus/onblur, not your div.

function notifyListeners () {
// update your DIV's
}

window.onfocus = notifyListeners ;

Sep 11 '06 #2
"zacware" <za*****@comcas t.netwrote in message
news:11******** *************@i 3g2000cwc.googl egroups.com...
I have an AJAX enabled page which contains a list of records out of a
database which are loaded into a div via an AJAX call.

If the user switches to another window, and comes back to this open
window later on, I want the list of records to be udpated when the
window is back in front

a simple onFocus doesn't work, as what happens is that if a button is
clicked on the window it causes the onfocus to fire as well

I've tried (unsuccessfully ) to block onfocus events from reaching the
window object from other objects (like buttons or images), but I can't
seem to get this to work

I just want the div to reload if the window gains focus!!!!!

there is surely something simple I am missing????

Will this help? Watch for word-wrap.

<html>
<head>
<title>winfocus .htm</title>
<script type="text/javascript">
function fokus() {
document.getEle mentById("when" ).innerHTML = new Date();
}
window.onload = fokus;
window.onfocus = fokus;
</script>
</head>
<body>
<div id="when" style="font-family:Arial"></div>
</body>
</html>
Sep 11 '06 #3
that's what I've done, the problem is that if I click on a button on
that page, the onfocus event from the button bubbles up to the window
object and refreshes the page too

I seem to have an event bubbling problem, and I am trying to figure out
how to only reload the div when the onfocus event is specifically
because of the window getting focus rather than a child element of the
window getting focus and trickling the event down to the window object.
McKirahan wrote:
"zacware" <za*****@comcas t.netwrote in message
news:11******** *************@i 3g2000cwc.googl egroups.com...
I have an AJAX enabled page which contains a list of records out of a
database which are loaded into a div via an AJAX call.

If the user switches to another window, and comes back to this open
window later on, I want the list of records to be udpated when the
window is back in front

a simple onFocus doesn't work, as what happens is that if a button is
clicked on the window it causes the onfocus to fire as well

I've tried (unsuccessfully ) to block onfocus events from reaching the
window object from other objects (like buttons or images), but I can't
seem to get this to work

I just want the div to reload if the window gains focus!!!!!

there is surely something simple I am missing????


Will this help? Watch for word-wrap.

<html>
<head>
<title>winfocus .htm</title>
<script type="text/javascript">
function fokus() {
document.getEle mentById("when" ).innerHTML = new Date();
}
window.onload = fokus;
window.onfocus = fokus;
</script>
</head>
<body>
<div id="when" style="font-family:Arial"></div>
</body>
</html>
Sep 11 '06 #4
"zacware" <za*****@comcas t.netwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
that's what I've done, the problem is that if I click on a button on
that page, the onfocus event from the button bubbles up to the window
object and refreshes the page too

I seem to have an event bubbling problem, and I am trying to figure out
how to only reload the div when the onfocus event is specifically
because of the window getting focus rather than a child element of the
window getting focus and trickling the event down to the window object.

This example doesn't have that problem.
Could you provide one that does?

<html>
<head>
<title>winfocus .htm</title>
<script type="text/javascript">
function fokus() {
document.getEle mentById("when" ).innerHTML = new Date();
}
window.onload = fokus;
window.onfocus = fokus;
</script>
</head>
<body>
<div id="when" style="font-family:Arial"></div>
<br><br><br>
<input type="button" value="clicking doesn't reload page">
</body>
</html>
Sep 11 '06 #5
add an img tag with an onclick handler in it, when you click on the
image the window's focus event will fire and the date will update

McKirahan wrote:
"zacware" <za*****@comcas t.netwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
that's what I've done, the problem is that if I click on a button on
that page, the onfocus event from the button bubbles up to the window
object and refreshes the page too

I seem to have an event bubbling problem, and I am trying to figure out
how to only reload the div when the onfocus event is specifically
because of the window getting focus rather than a child element of the
window getting focus and trickling the event down to the window object.


This example doesn't have that problem.
Could you provide one that does?

<html>
<head>
<title>winfocus .htm</title>
<script type="text/javascript">
function fokus() {
document.getEle mentById("when" ).innerHTML = new Date();
}
window.onload = fokus;
window.onfocus = fokus;
</script>
</head>
<body>
<div id="when" style="font-family:Arial"></div>
<br><br><br>
<input type="button" value="clicking doesn't reload page">
</body>
</html>
Sep 11 '06 #6
"zacware" <za*****@comcas t.netwrote in message
news:11******** **************@ q16g2000cwq.goo glegroups.com.. .
add an img tag with an onclick handler in it, when you click on the
image the window's focus event will fire and the date will update
It didn't for me under IE5.5 but under Firefox it updates the time
wherever I click on the page.

<html>
<head>
<title>winfocus .htm</title>
<script type="text/javascript">
function click() {
alert("click!") ;
}
function fokus() {
document.getEle mentById("when" ).innerHTML = new Date();
}
window.onload = fokus;
window.onfocus = fokus;
</script>
</head>
<body>
<div id="when" style="font-family:Arial"></div>
<br><br><br>
<img src="clear.gif" border="1" width="20" height="20" onclick="click( )">
</body>
</html>

What browser (and version) are you testing with?
Sep 11 '06 #7
FireFox 1.5, so I guess this is a browser specific issue!
McKirahan wrote:
"zacware" <za*****@comcas t.netwrote in message
news:11******** **************@ q16g2000cwq.goo glegroups.com.. .
add an img tag with an onclick handler in it, when you click on the
image the window's focus event will fire and the date will update

It didn't for me under IE5.5 but under Firefox it updates the time
wherever I click on the page.

<html>
<head>
<title>winfocus .htm</title>
<script type="text/javascript">
function click() {
alert("click!") ;
}
function fokus() {
document.getEle mentById("when" ).innerHTML = new Date();
}
window.onload = fokus;
window.onfocus = fokus;
</script>
</head>
<body>
<div id="when" style="font-family:Arial"></div>
<br><br><br>
<img src="clear.gif" border="1" width="20" height="20" onclick="click( )">
</body>
</html>

What browser (and version) are you testing with?
Sep 11 '06 #8
"zacware" <za*****@comcas t.netwrote in message
news:11******** **************@ p79g2000cwp.goo glegroups.com.. .
FireFox 1.5, so I guess this is a browser specific issue!
Don't run this under Firefox....
You'll have to use Ctrl+Alt+Delete to end the task!

<html>
<head>
<title>winfocus .html</title>
<script type="text/javascript">
function click() {
alert("click");
}
function fokus1() {
alert("onload") ;
document.getEle mentById("when" ).innerHTML = new Date();
}
function fokus2() {
alert("onfocus" );
document.getEle mentById("when" ).innerHTML = new Date();
}
window.onload = fokus1;
window.onfocus = fokus2;
</script>
</head>
<body>
<div id="when" style="font-family:Arial"></div>
<br>
<img src="clear.gif" border="1" width="20" height="20" onclick="click( )">
</body>
</html>
Sep 12 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
2859
by: Benno Bös | last post by:
If I use the following construct in the frame "main" for a link to an extern site: <A HREF="http://www.any.xy" TARGET="extern"> the Browser is creating the window "extern", loading the page www.any.xy an setting the focus to "extern". But when I go return to "main" without closing "extern", a click to an other link (e.g. www.2nd_any.xy) on "main" does not setting the focus to "extern".
17
2742
by: Zvi Danovich | last post by:
Hi, I am a newby in ASP.NET, and till now wrote only simple "classic" WEB-sites. But - the time came, and now I need that: 1. Server will "listen" for some events on its local machine 2. According to event received (say - event ID), it will update client pages, that need updating based on this ID (if currently there exist clients that are interesting in specific ID). The good example of such site - airport flight information, when...
9
12991
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from northwind database that has an employees, orders, and order details. the following are the 3 tables in my sql database students schyrsem
13
2282
by: Richard Shewmaker | last post by:
I've only recently returned to (trying to) doing simple JS, so this is probably a really lame question. I have a Web page with a series of graphics in it (window A). Clicking on a graphic in A opens a small pop-up window (window B) over A. If the visitor clicks on B, it closes. If the visitor clicks back on A -- the page or a new graphic -- A comes
9
7756
bhcob1
by: bhcob1 | last post by:
Hey guys, 'Update or CancelUpdate without AddNew or Edit' On my database i keep occasionly get this error when i try and edit a field, it is not everytime. It will be working fine and then this error appears. I will be editing records and then a random one will get the error. A bit of background on my form, this will seem a bit lengthy but here is my code. The form has a navigation list which the user can select a record to view. An...
3
1525
by: John | last post by:
I'm rendering a Html Select to auto dropdown when created, it works but losses it's normal mouseover effect of highlighting each row and the type a letter to move to a macthing row functions. If I try to type or click it to give it focus again it just fires the changed event. Any Ideas as to how I can modify this to function properly? var formFld = document.createElement('select') formFld.setAttribute('size', '15')...
11
5327
by: V S Rawat | last post by:
using Javascript, I am opening a web-based url in a popup window. MyWin1=Window.Open(url, "mywindow") There is a form (form1) in the url in that popup window, I need to submit that form. How do I submit that form1 from the javascript from my current window? Thanks.
0
9710
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9589
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10593
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9163
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7626
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.