473,795 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript looses mind on resize event

I am having a problem that is driving me crazy and I am whits end. I am
hoping that someone here can help me. I have a client server application
where the client is drawing a progressive bar graph based on data
retrieved from the server once a second. The basic loop looks like this;

</HEAD>
<script language="JavaS cript1.2">

var nodedatareq;
function buildGraphs() {

document.writel n("<BODY>");

// build graphs and add them

document.writel n("</BODY>");

window.addEvent Listener("resiz e",resizeEventH andler, false);
}

function initXMLHTTPRequ est() {
var xreq= null
if( window.XMLHttpR equest ) {
xreq= new XMLHttpRequest( )
} else if(window.Activ eXObject) {
xreq= new ActiveXObject(" Microsoft.XMLHT TP")
}
return xreq
}

function sendNodeRequest ()
{
var mnodedataod="PO ST";
nodedatareq = initXMLHTTPRequ est();
if( nodedatareq ) {
nodedataParam = "nodedata=" + escape(1)
nodedatareq.onr eadystatechange =nodedataHandle r
nodedatareq.ope n(mnodedataod,s erverURL,true)
nodedatareq.set RequestHeader(" Content-Type",
"applicatio n/x-www-form-urlencoded")
nodedatareq.sen d(nodedataParam )
}
}

function nodedataHandler () {

var ready= nodedatareq.rea dyState
var respStr=null
var index
if( ready == READY_STATE_COM PLETE ) {
respStr=nodedat areq.responseTe xt

// plot data

timer = setTimeout(send NodeRequest, 1000)
}
}
function resizeEventHand ler(target, e)
{
// do nothing
}

buidGraphs()
timer = setTimeout(send NodeRequest, 1000)
</script>

This works fine advancing the graphs and looping until I resize the
window. Once I do that the first time it reenters sendNodeRequest () I
get an error that initXMLHTTPRequ est is undefined. I tried inlining the
code for initXMLHTTPRequ est into sendNodeRequest but then it complains
thay nodedatareq is undefined. It is as if it has completely lost all of
its history and has no context or scope.

I have tried using

window.onresize = function(e) {resizeEventHan dler(e);};

instead of window.addEvent Listener. I tried

window.onresize = function(e) {resizing = 1;};

so it didn't have to call a function, but that had the same results.

I also tried putting the call to window.addEvent Listener before the call
to buildGraphs. Then it didn't die but the event was not seviced either.

Anyone have any suggestions?

Thanks

Howard
Dec 16 '06 #1
6 2751
Howard wrote:

If you don't return false in your event handlers, the browsers will
quite cheerfully continue in their default behavior, the kind which is
driving you crazy. Once you start returning false they will do what you
ask and no more.
window.onresize = function(e) {resizeEventHan dler(e);};

instead of window.addEvent Listener. I tried

window.onresize = function(e) {resizing = 1;};

so it didn't have to call a function, but that had the same results.
window.onresize = function(e) {resizeEventHan dler(e); return false};
window.onresize = function(e) {resizing = 1; return false};

function resizeEventHand ler(target, e)
{
// do nothing and fail, return false for teh win
return false;
}

Note that not all browsers pass e.

if (e == null) { e = window.event; }

will make the code more cross browser compliant.

No idea why a resize event would trip your application up, not enough
information was supplied in the pseudo code. So there's no guarantee
this will work.

G'luck.

--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA
Dec 16 '06 #2
Howard wrote:
I am having a problem that is driving me crazy and I am
whits end. I am hoping that someone here can help me. I
have a client server application where the client is
drawing a progressive bar graph based on data retrieved
from the server once a second. The basic loop looks
like this;

</HEAD>
<script language="JavaS cript1.2">
^^^
This is silly in a script that requires the use of an XML HTTP request
object. You certainly do not want browsers that support the aberrant
type-conversion and alternative syntax of JavaScript 1.2 to actually
employ that language version.
>
var nodedatareq;
function buildGraphs() {

document.writel n("<BODY>");

// build graphs and add them

document.writel n("</BODY>");

window.addEvent Listener("resiz e",resizeEventH andler, false);
}
<snip>
This works fine advancing the graphs and looping until I
resize the window. Once I do that the first time it reenters
sendNodeRequest () I get an error that initXMLHTTPRequ est is
undefined. I tried inlining the code for initXMLHTTPRequ est
into sendNodeRequest but then it complains thay nodedatareq
is undefined. It is as if it has completely lost all of its
history and has no context or scope.
<snip>

That is precisely what has happened. If you use -document.write - or
document.writel n - after the original document has loaded you are
re-opening the document, removing all of its existing contents, and
associated script functions and variables, and replacing the document
from scratch. You may not be calling either of the - write - methods
after the first loading of the document (though you also may as the
request is asynchronous and the time for the response to start will be
influenced by many factors, including network traffic), but as soon as
you re-size handler re-calls the method that does the wiring the current
document, and associated scripts, are removed and replaced.

Richard.
Dec 16 '06 #3
Lee
Howard said:
>
I am having a problem that is driving me crazy and I am whits end.
You're at the end of the smallest part imaginable because
Javscript seems to be allowing it's mind to run loose?
--

Dec 16 '06 #4
Thank you for your response

Richard Cornford wrote:
Howard wrote:
<snip>
></HEAD>
<script language="JavaS cript1.2">
^^^
This is silly in a script that requires the use of an XML HTTP request
object. You certainly do not want browsers that support the aberrant
type-conversion and alternative syntax of JavaScript 1.2 to actually
employ that language version.
So, I am better off just using <scriptor some other version

<snip>
but as soon as
you re-size handler re-calls the method that does the wiring the current
document, and associated scripts, are removed and replaced.
I am not sure what you are saying here (a function of my lack of
knowledge I am sure). Is the location of my setting the callback the
problem or is the act of having a callback on the window object the
problem? I have tried moving the setting of the callback to other
locations in the script outside the <body>...</bodysection. If I move
the setting to before it, the callback never gets called. If I move it
after I get the same undefined. If setting the callback on the window
object is the problem, where is a better place to put it?

Thanks again

Howard

>
Richard.

Dec 18 '06 #5
Lee
Howard said:
>
Thank you for your response

Richard Cornford wrote:
>Howard wrote:

<snip>
>></HEAD>
<script language="JavaS cript1.2">
^^^
This is silly in a script that requires the use of an XML HTTP request
object. You certainly do not want browsers that support the aberrant
type-conversion and alternative syntax of JavaScript 1.2 to actually
employ that language version.

So, I am better off just using <scriptor some other version

<snip>
>but as soon as
you re-size handler re-calls the method that does the wiring the current
document, and associated scripts, are removed and replaced.

I am not sure what you are saying here (a function of my lack of
knowledge I am sure). Is the location of my setting the callback the
problem or is the act of having a callback on the window object the
problem?
Your script tag should be:
<script type="text/javascript">

The problem is that you use document.write after the page has loaded.
The first thing document.write( ) does is to clear the page memory.
You need to choose another method of updating the page, such as
changing the innerHTML property of some component.
--

Dec 18 '06 #6
Got it, and fixed it. Thanks

Howard
Lee wrote:
Howard said:
>Thank you for your response

Richard Cornford wrote:
>>Howard wrote:
<snip>
>>></HEAD>
<script language="JavaS cript1.2">
^^^
This is silly in a script that requires the use of an XML HTTP request
object. You certainly do not want browsers that support the aberrant
type-conversion and alternative syntax of JavaScript 1.2 to actually
employ that language version.
So, I am better off just using <scriptor some other version

<snip>
>>but as soon as
you re-size handler re-calls the method that does the wiring the current
document, and associated scripts, are removed and replaced.
I am not sure what you are saying here (a function of my lack of
knowledge I am sure). Is the location of my setting the callback the
problem or is the act of having a callback on the window object the
problem?

Your script tag should be:
<script type="text/javascript">

The problem is that you use document.write after the page has loaded.
The first thing document.write( ) does is to clear the page memory.
You need to choose another method of updating the page, such as
changing the innerHTML property of some component.

Dec 19 '06 #7

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

Similar topics

2
12792
by: Put 030516 in email subj to get thru | last post by:
I've always been bothered about having to statically declare the size of a Java applet window (container?) in the calling HTML. I've always wanted the moral equivalent of width=50% statement (of the window or frame). I'm trying to use Javascript to do so. I can sort of get an example working in a Mozilla browser: > <!-- This works on Mozilla only (and maybe netscape) --> > <script language="Javascript"> > document.write( "<applet...
9
2901
by: Robby Bankston | last post by:
I'm working on some code and am running into brick walls. I'm trying to write out Javascript with Javascript and I've read the clj Meta FAQ and didn't see the answer, read many similar posts (with no luck though), and searched through the IRT.ORG Faqs (www.irt.org/script/script.htm). The Javascript is designed to open an popup window and then inside that window call another script which will resize that window. There may be another...
1
18853
by: den2005 | last post by:
Hi everybody, I am confused and still looking why this codes is not working. Can anyone notice or know why this code is not working? Thanks in advance. Code working: <form id="form1" runat="server"> <div> &nbsp;</div> <div>
1
3929
by: jadeite100 | last post by:
Hi: I am using IE 6 SP2. My resize attribute does not work <body onresize="test1();">. When I resize my window, the resize event doesnot get call. I have a jsp page with an iFrame called test1.jsp. The iFrame src points to a page called test2.jsp. It has a resize attribute that calls a javascript function that is located in test1.jsp. In the test2.jsp page, it doesn't recognize the function that is located in test1.jsp page. Is there...
0
10216
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
10165
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
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
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...
0
6783
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
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.