473,651 Members | 3,012 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9964
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.onafter resize 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.bo dy.offsetWidth;
if(v && (1<v)&&!(x<v)) // scrollbar width problem
x=v-1;
y=w.innerHeight ;
sx=w.pageXOffse t||0;
sy=w.pageYOffse t||0;
}
else
{ d=w.document;
if(d.body)
{ b=d.documentEle ment.clientWidt h?
d.documentEleme nt:d.body; // IE 6 strict dtd
x=b.clientWidth ||0;
y=b.clientHeigh t||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.clearTim eout(this.timer Id);
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.onafterres ize();
}
},
onafterresize: function()
{ alert("missing line: \n " +
"oResize.onafte rresize = callBackFunctio n;")
}
}

// 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.onafter resize 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.bo dy.offsetWidth;
if(v && (1<v)&&!(x<v)) // scrollbar width problem
x=v-1;
y=w.innerHeight ;
sx=w.pageXOffse t||0;
sy=w.pageYOffse t||0;
}
else
{ d=w.document;
if(d.body)
{ b=d.documentEle ment.clientWidt h?
d.documentEleme nt:d.body; // IE 6 strict dtd
x=b.clientWidth ||0;
y=b.clientHeigh t||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.clearTim eout(this.timer Id);
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.onafterres ize();
}
},
onafterresize: function()
{ alert("missing line: \n " +
"oResize.onafte rresize = callBackFunctio n;")
}
}

// 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
7125
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
2727
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"> <html> <head> <title>Test window.onresize</title> <script type="text/javascript"> function resize_func() {
2
97089
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 script tag in the <head>: <script type="text/javascript"> window.onresize = doResize; </script>
2
3822
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 the onresize event while it is being resized. What I'm wondering is - does anyone have any suggestions on making the script function only once, after the last onresize event, rather than on every one? I've done some searching, but I'm not...
2
2026
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 course that's after the HTTP request. Here is the code: <HTML> <HEAD> <script language="javascript"> function Loadit() { var oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
2
8100
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 in IE if the window has a handler for onresize, and the user clicks to maximize the window, the handler gets called BEFORE the window is maximized. So the size is the size before maximizing, rather than after. (In
8
7855
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 this?
2
5207
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 do what I need. The javascript solution assigns a function to window.onresize that sets the inline style, it works with one problem -- the handler only gets called after the resizing stops, and so there is noticeable lag before it redraws.
0
8278
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
8807
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...
1
8466
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
7299
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
6158
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
5615
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
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...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1912
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.