473,414 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

onResize is called many times

Bas
Hello all,

I'm trying to create a little script which will save the width of a
certain frame into a database, so that every user still has his/her
"own" frame width when logging back on. Now, this works ok, though
there's one little problem left: when i click the frameborder and drag
it around in IE (it's not working in NN, but that's not my goal since
it's a very specific CMS) the onResize handler is called literally
hundreds of times.

I've only found some pages on the web describing that IE calls
onResize twice. Has anyone come across this problem, or does anyone
might have a workaround for this?

Thanks in advance,
Bas
Jul 20 '05 #1
2 9944
Bas wrote:
....
when i click the frameborder and drag
it around in IE (it's not working in NN, but that's not my goal since
it's a very specific CMS) the onResize handler is called literally
hundreds of times.

I've only found some pages on the web describing that IE calls
onResize twice. Has anyone come across this problem, or does anyone
might have a workaround for this?


I think IE generates resize events when the mouse moves, even though the
mouse button is down and the operation hasn't finished yet. Since the
event object's button property reports zero during resize, it doesn't
appear to be of much help in the matter.

One possibility would be to record the window size, and use a timer to
determine if resizing has stopped, for a second say, before doing
anything about it. For the following code example, set
oResize.onafterresize to a function you want to call after resize has
stopped:
// existing function to find window dimensions and scroll amount:

function dfxWinXY(w) // w = window object
{
var b,d,x,y,sx,sy,v;
x=y=sx=sy=0;
if(w.innerWidth && w.innerHeight)
{ x=w.innerWidth;
v=w.document.body.offsetWidth;
if(v && (1<v)&&!(x<v)) // scrollbar width problem
x=v-1;
y=w.innerHeight;
sx=w.pageXOffset||0;
sy=w.pageYOffset||0;
}
else
{ d=w.document;
if(d.body)
{ b=d.documentElement.clientWidth?
d.documentElement:d.body; // IE 6 strict dtd
x=b.clientWidth||0;
y=b.clientHeight||0;
sx=b.scrollLeft||0;
sy=b.scrollTop||0;
}
}
return {x:x,y:y,sx:sx,sy:sy};
}

// object to bundle resize processing:

window.oResize = {
checkTime: 1000,
oldXY: dfxWinXY( window),
timerId: 0,
check1: function() {window.oResize.check2()},
check2: function() // call as method of oResize
{ if(this.timerId)
window.clearTimeout(this.timerId);
this.timerId =
setTimeout( "window.oResize.check3()",this.checkTime);
},
check3: function()
{
var newXY = dfxWinXY( window);
this.timerId = 0;
if( (newXY.x != this.oldXY.x) ||
(newXY.y != this.oldXY.y))
{ this.oldXY = newXY;
this.onafterresize();
}
},
onafterresize: function()
{ alert("missing line: \n " +
"oResize.onafterresize = callBackFunction;")
}
}

// start resize monitoring:

window.onresize= oResize.check1;
--

HTH

Dom
Jul 20 '05 #2
Bas
Dom Leonard <do*************@senet.andthis.com.au> wrote in message news:<8P****************@nnrp1.ozemail.com.au>...
One possibility would be to record the window size, and use a timer to
determine if resizing has stopped, for a second say, before doing
anything about it. For the following code example, set
oResize.onafterresize to a function you want to call after resize has
stopped:
// existing function to find window dimensions and scroll amount:

function dfxWinXY(w) // w = window object
{
var b,d,x,y,sx,sy,v;
x=y=sx=sy=0;
if(w.innerWidth && w.innerHeight)
{ x=w.innerWidth;
v=w.document.body.offsetWidth;
if(v && (1<v)&&!(x<v)) // scrollbar width problem
x=v-1;
y=w.innerHeight;
sx=w.pageXOffset||0;
sy=w.pageYOffset||0;
}
else
{ d=w.document;
if(d.body)
{ b=d.documentElement.clientWidth?
d.documentElement:d.body; // IE 6 strict dtd
x=b.clientWidth||0;
y=b.clientHeight||0;
sx=b.scrollLeft||0;
sy=b.scrollTop||0;
}
}
return {x:x,y:y,sx:sx,sy:sy};
}

// object to bundle resize processing:

window.oResize = {
checkTime: 1000,
oldXY: dfxWinXY( window),
timerId: 0,
check1: function() {window.oResize.check2()},
check2: function() // call as method of oResize
{ if(this.timerId)
window.clearTimeout(this.timerId);
this.timerId =
setTimeout( "window.oResize.check3()",this.checkTime);
},
check3: function()
{
var newXY = dfxWinXY( window);
this.timerId = 0;
if( (newXY.x != this.oldXY.x) ||
(newXY.y != this.oldXY.y))
{ this.oldXY = newXY;
this.onafterresize();
}
},
onafterresize: function()
{ alert("missing line: \n " +
"oResize.onafterresize = callBackFunction;")
}
}

// start resize monitoring:

window.onresize= oResize.check1;


Dom,

Thanks for your answer :) I've thought of a timer, but it wouldn't be
100% perfect. When you would hold the mouse pressed down and not move
it for 1 second, it would trigger the function. And if you are very
fast, you could click some url on the page, and have the function not
triggered at all :)

I know, i'm a purist, but after reading your post, i realized
something: I could add an onMouseUp to the <body> tag, and when the
event is triggered, it would check if the window size differs from the
original width. If it does, save it :)

Thanks! :P
Jul 20 '05 #3

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

Similar topics

2
by: David | last post by:
Greetings, Does anyone know of a workaround for the onresize bug in Firefox? <body onresize="history.go(0)"> I've looked all around and can't seem to find a working workaround. David
1
by: Darrel Yurychuk | last post by:
I'm having a problem getting the window.onresize to work properly. Here is a simple test case I wrote: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">...
2
by: Tony | last post by:
If I want to call a function (call it doResize) when the browser window is resized, is it better to put that in the body tag: <body onresize="doResize()"> Or is it better to put the call in a...
2
by: Tony | last post by:
I have a script that is called by the window.onresize event. The problem is that the script is called multiple times when I'm resizing the window in IE - obviously, because IE continuously fires...
2
by: FrankIsHere | last post by:
This should attach the event to the onresize of the window object, but when I try to resize the browser after executing the page it does not work... only after I refresh the page. But then of...
2
by: mitch | last post by:
In IE, I'm having problems with these events. What I'm trying to do is get the size of the window after the user has resized it, either by dragging the corner or by maximizing. It seems like...
8
by: David Gravereaux | last post by:
Hi, I'm using chunked transfer-coding to send an "unending" page, but IE _NEVER_ fires onresize events until the page is finished. Unfortunately, the page never is "finished". How do I handle...
2
by: yb | last post by:
I am attempting to modify the style of an element (its width) as the window is being resized, in firefox. Long story short, I've tried to use CSS but one particular part of the layout just won't...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.