Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML Script bombing after a few hours....

Status
Not open for further replies.

jmalge

MIS
Aug 3, 2012
7
US
Hi all.

I'm new to a company and we run SolarWinds here for our network monitoring. There is a home grown script that runs our call center. When I upgraded SolarWinds recently, the home grown script now bombs out after a few hours. I don't know much about scripting so I was wondering if someone could take a look at this script and see if there is anything that you see that would make this bomb after a certain amount of time.

I greatly appreciate any help I can get. (Remember, I didn't write this so don't blast me if it's horribly written) :)

<html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<head>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
var iframeSrc = new Array;
//iframeSrc[0] = "//iframeSrc[1] = "//iframeSrc[2] = "//iframeSrc[3] = "iframeSrc[0] = "iframeSrc[1] = "iframeSrc[2] = "iframeSrc[3] = "//Look into using NetworkMap.aspx instead of MapView.aspx...
var intervalVar;
var interval = 30; // seconds between iframe switching
var currentSrc = 0;
var lastPage = iframeSrc.length - 1;
var playing = false;


function switchPage() {
var randomnumber=Math.floor(Math.random()*100000);
$('#myIframe').fadeTo(1000,0,function() {
currentSrc++;
if (currentSrc > lastPage) currentSrc = 0;
document.getElementById("myIframe").src = iframeSrc[currentSrc] + "&amp;random=" + randomnumber;
}).fadeTo(1000,1);
}


function slideshow() {
if (playing) {
playing = false;
clearInterval(intervalVar);
}
else {
playing = true;
intervalVar = setInterval(switchPage, interval * 1000);

}
}
function loadpage() {
document.getElementById("myIframe").src = iframeSrc[0];
slideshow();
}
</script>
<title>Support Page Viewer</title>
</head>
<body leftmargin="0" topmargin="0" onload="loadpage()">

<iframe id="myIframe" src="" width="75%" scrolling="NO" frameborder="0" height="75%" ></iframe>
<iframe id="callsframe" src=" width="25%" scrolling="NO" height="75%"></iframe>
<iframe id="agentsframe" src=" width="100%" height="25%" scrolling="no" marginheigh="0" marginwidth="0"></iframe>

</body>
</html>
 

There's no such thing as an HTML script. HTML is a static language. This is basically a simple Javascript script which loads a random page every 30 seconds.

What browser is this running on?
Define
bombs out
?

How is solarWinds involved?

Anyway as a guess:
Its conceivable that the setInterval function, since it never ends really, is consuming more and more memory each time it loads a new page eventually causing the browser to hang because there's no more memory available to use.
I would check the CPU usage at the time of the crash to see if that is the cause.

Another culprit could be the pages being loaded. The server may stop responding at some time, and cause the pages to no longer load.


For future reference, any Javascript related question should be posted in forum216


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Thanks for the response and sorry I wasn't more clear.

The browser is Internet Explorer 8.

When I say bombs out, the pictures or "maps" bring up a red x instead of actually showing the picture. The only way to get this corrected is to refresh the page.

SolarWinds is involved because the netmon links are accessing SolarWinds web based maps that monitor our network, which are below

frameSrc[0] = "iframeSrc[1] = "iframeSrc[2] = "iframeSrc[3] = "
It very well could be an IE8 issue as well, however SolarWinds support told me that IE8 is supported by the new revisions that we upgraded to.
 
The script loads entire pages, SO I would be checking just what the value of the Src attribute is at the time it bombs out.

Also when it bombs out if you open the page directly does it show up correctly?

The Javascript itself looks o.k. Maybe the server is getting congested with so many requests. 30 seconds may be to little.

I would start looking at your network and server load, when the loading fails. Also make s sure that the script is actually not working any more. That is it stops trying to load the iframes. you can do that by adding an output log. so it shows something each time it runs the function. displaying the time and date of the last execution is a good choice. As you can tel if its more than 30 seconds ago, the script hasn't run again, but if its less, then it has, and the issue is somewhere else.

HTML:
<body leftmargin="0" topmargin="0" onload="loadpage()">
<div id="timestamp"></div>
<iframe id="myIframe" src="" width="75%" scrolling="NO" frameborder="0" height="75%" ></iframe>

Code:
function switchPage() {
[b][COLOR=red]var now = new Date();
var mytime = now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
document.getElementById('timestamp').innerHTML = mytime;[/color][/b]
var randomnumber=Math.floor(Math.random()*100000);
$('#myIframe').fadeTo(1000,0,function() { 
currentSrc++;
if (currentSrc > lastPage) currentSrc = 0;
document.getElementById("myIframe").src = iframeSrc[currentSrc] + "&amp;random=" + randomnumber;
}).fadeTo(1000,1); 
}







----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Why not use a self-referencing meta refresh? It would be less resource intensive than what a javascript timer reload is.

Code:
<meta http-equiv="refresh" content="nn;url=">[code]

Replace nn with the appropriate number of seconds, and leaving the url parameter empty means it will simply refresh the current URL.



Chris.

Indifference will be the downfall of mankind, but who cares?
[b]Time flies like an arrow, however, fruit flies like a banana.[/b]
[url=http://webmaster-talk.eu]Webmaster Forum[/url]
 
Chris,

I appreciate your response. I've officially found out that it's this page is causing the memory to run crazy after a few hours, which is causing it to hang up. So I like your idea if it means it will lessen our resources.

However, I'm not entirely sure what I need to remove so I can try your code. Could you possibly expound a little bit? My apologies, I'm not a programmer.

 
Chris is stating to replace your JavaScript page refresh with the meta tag refresh. They are functionally equivalent, but the meta tag is less resource intensive, as it's up to the browser itself to refresh the page.

Comment out the Javascript calls and add the meta tag to the head of the page.

Lodlaiden

You've got questions and source code. We want both!
There's a whole lot of Irish in that one.
 
Thanks for the responses everyone.

I'm not going to lie, I'm still pretty confused on the instructions.

Qik, when I replace the Java code, is that only the lines at the top which have "java" in them, or do I replace the var commands in the middle as well?

Also, it appears that when I make a change, it messes the frames up. It basically puts everything in a straight line instead of organizing the frames.

I seem to be going backwards at this point.
 
if you are not that adept at JS then just make the JS interval like 99999999 seconds and add the meta refresh until you can clear the JS issue.

See if that helps out in the interim.

Darryn Cooke
| Marketing and Creative Services
 
Wow, clearly nobody has bothered to actually read what the JS code is doing.

The Meta refresh isn't going to do anything useful in this scenario. The Js is not only refreshing the iframe, its also changing the src and the src URL by moving a counter along and adding a random parameter to it which I'm going to assume makes the src modify its contents in some fashion.

With that said, I think the option here would be to have the refresh kill the interval every so often to see if that releases memory.

Code:
var now = new Date();
var timeKeeper = now.getHour();

function switchPage() {
var now2 = new Date();
var newHour = now.getHour();
if(newHour > timekeeper)
{
  playing=true;
  slideshow();
  timekeeper = newHour;
  slideshow();
  var randomnumber=Math.floor(Math.random()*100000);
  ...

This should kill off the interval running about every hour, hopefully release memory, and start it off again, as per the slideshow function.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Vacunita,

The explanation you gave makes me like your approach a lot. In fact, it sounds like it's exactly what this script needs. I'm just a little fuzzy on your code.

Do I replace only these 2 vars

var intervalVar;
var interval = 30; // seconds between iframe switching

with

var now = new Date();
var timeKeeper = now.getHour();

or do I replace all of the var's ?

Also,

function switchPage() {
var now2 = new Date();
var newHour = now.getHour();
if(newHour > timekeeper)
{
playing=true;
slideshow();
timekeeper = newHour;
slideshow();
var randomnumber=Math.floor(Math.random()*100000);

Is that the entire switchpage function? As in, do I replace the switchpage function for this entire piece of code? I'm trying to figure it out and play with it, but it seems whatever I do isn't bringing the page up correctly. In fact, it doesn't appear to be showing the netmon links that are listed in the code. So obviously I"m putting in something incorrectly.
 
I could have sworn I answered this.

Anyway,

No, the code goes where your current code is. I just added a couple things before the switchpage function, and inside it.

New code in red, your original code in black.

Code:
<html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<head>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
var iframeSrc = new Array;
//iframeSrc[0] = "[URL unfurl="true"]http://netmon:8080/NetPerfMon/MapView.asp?Map=M:No...";[/URL]
//iframeSrc[1] = "[URL unfurl="true"]http://netmon:8080/NetPerfMon/MapView.asp?Map=M:Fi...";[/URL]
//iframeSrc[2] = "[URL unfurl="true"]http://netmon:8080/NetPerfMon/MapView.asp?Map=M:Ov...";[/URL]
//iframeSrc[3] = "[URL unfurl="true"]http://netmon:8080/NetPerfMon/MapView.asp?Map=M:Eu...";[/URL]
iframeSrc[0] = "[URL unfurl="true"]http://netmon:8080/Orion/NetPerfMon/MapView.aspx?M..."[/URL]
iframeSrc[1] = "[URL unfurl="true"]http://netmon:8080/Orion/NetPerfMon/MapView.aspx?M..."[/URL]
iframeSrc[2] = "[URL unfurl="true"]http://netmon:8080/Orion/NetPerfMon/MapView.aspx?M..."[/URL]
iframeSrc[3] = "[URL unfurl="true"]http://netmon:8080/Orion/NetPerfMon/MapView.aspx?M..."[/URL]
//Look into using NetworkMap.aspx instead of MapView.aspx...
var intervalVar;
var interval = 30; // seconds between iframe switching
var currentSrc = 0;
var lastPage = iframeSrc.length - 1;
var playing = false;

[red]var now = new Date();
var timeKeeper = now.getHour();[/red]

function switchPage() {

[red]var now2 = new Date();
var newHour = now.getHour();
if(newHour > timekeeper)
{
playing=true;
slideshow();
timekeeper = newHour;
slideshow();
}
[/red]
var randomnumber=Math.floor(Math.random()*100000);
$('#myIframe').fadeTo(1000,0,function() { 
currentSrc++;
if (currentSrc > lastPage) currentSrc = 0;
document.getElementById("myIframe").src = iframeSrc[currentSrc] + "&amp;random=" + randomnumber;
}).fadeTo(1000,1); 
}


function slideshow() {
if (playing) {
playing = false;
clearInterval(intervalVar);
}
else {
playing = true;
intervalVar = setInterval(switchPage, interval * 1000);

}
}
function loadpage() {
document.getElementById("myIframe").src = iframeSrc[0];
slideshow();
}
</script>
<title>Support Page Viewer</title>
</head>
<body leftmargin="0" topmargin="0" onload="loadpage()">

<iframe id="myIframe" src="" width="75%" scrolling="NO" frameborder="0" height="75%" ></iframe>
<iframe id="callsframe" src="[URL unfurl="true"]http://"server"/wallboard/servicedesk.asp?sendmailenabled=true"[/URL] width="25%" scrolling="NO" height="75%"></iframe>
<iframe id="agentsframe" src="[URL unfurl="true"]http://"server"/wallboard/sd-agent.asp"[/URL] width="100%" height="25%" scrolling="no" marginheigh="0" marginwidth="0"></iframe>

</body>
</html>




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Vacunita,

while that JS code may change src urls after each 30s, it also does so at the initial run, doesn't it?

Therefore that already proposed solution will work.

Increasing the JS timeout to more than 30 seconds (60 would be sufficient) and adding the meta tag should indeed be sufficient to do the same thing. Jmalge also said that after the page bombs, a refresh of it solves the problem, which supports the idea, a meta auto refesh will help.

That means just change
var interval = 30;
to eg
var interval = 60;

And add the meta refresh code right after <head>. Meta tags are meant to be anywhere between <head> and </head> of an html page.

So change
<head>
to
<head><meta http-equiv="refresh" content="30;url=">

That makes every JS code unused, that will be done after the interval has elapsed, but leaving that as is, will also not harm. It never get's the chance to run anyway, as the meta tag causes an earlier referesh.

Bye, Olaf.
 
Olaf,
while that JS code may change src urls after each 30s, it also does so at the initial run, doesn't it?

Therefore that already proposed solution will work.
Not quite.

The code changes the frame sources sequentially each time it runs, keeping a counter. The meta refresh will reset this counter every time, essentially leaving the frame in the same source, and not cycle through them.

However, the meta refresh may work once every hour or so rather than every 30 seconds to release memory usage.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top