473,387 Members | 1,892 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,387 software developers and data experts.

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="JavaScript1.2">

var nodedatareq;
function buildGraphs() {

document.writeln("<BODY>");

// build graphs and add them

document.writeln("</BODY>");

window.addEventListener("resize",resizeEventHandle r, false);
}

function initXMLHTTPRequest() {
var xreq= null
if( window.XMLHttpRequest ) {
xreq= new XMLHttpRequest()
} else if(window.ActiveXObject) {
xreq= new ActiveXObject("Microsoft.XMLHTTP")
}
return xreq
}

function sendNodeRequest()
{
var mnodedataod="POST";
nodedatareq = initXMLHTTPRequest();
if( nodedatareq ) {
nodedataParam = "nodedata="+ escape(1)
nodedatareq.onreadystatechange=nodedataHandler
nodedatareq.open(mnodedataod,serverURL,true)
nodedatareq.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded")
nodedatareq.send(nodedataParam)
}
}

function nodedataHandler() {

var ready= nodedatareq.readyState
var respStr=null
var index
if( ready == READY_STATE_COMPLETE ) {
respStr=nodedatareq.responseText

// plot data

timer = setTimeout(sendNodeRequest, 1000)
}
}
function resizeEventHandler(target, e)
{
// do nothing
}

buidGraphs()
timer = setTimeout(sendNodeRequest, 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 initXMLHTTPRequest is undefined. I tried inlining the
code for initXMLHTTPRequest 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) {resizeEventHandler(e);};

instead of window.addEventListener. 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.addEventListener 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 2723
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) {resizeEventHandler(e);};

instead of window.addEventListener. 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) {resizeEventHandler(e); return false};
window.onresize = function(e) {resizing = 1; return false};

function resizeEventHandler(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="JavaScript1.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.writeln("<BODY>");

// build graphs and add them

document.writeln("</BODY>");

window.addEventListener("resize",resizeEventHandle r, 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 initXMLHTTPRequest is
undefined. I tried inlining the code for initXMLHTTPRequest
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.writeln - 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="JavaScript1.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="JavaScript1.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="JavaScript1.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
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...
9
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...
1
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"...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.