Click to See Complete Forum and Search --> : Problem with scrolling script


alex80it
07-03-2003, 05:02 AM
Hi all!
I enclose a copy of the page that troubles me.
I translated all the function names in English, since they were in Italian, but that shouldn't change a thing...
The idea is to have an announcement page that scrolls automatically and cycles forever once it has done scrolling.
I did this by putting the same stuff on thwo pages, and maing them scroll one after the other, and starting all over again. The announcements are taken from an asp page that queries an announcement DB.
Here is the code:

<HTML>
<HEAD>
<TITLE>Annunci</TITLE>
<STYLE TYPE="text/css">
A.newslink {
text-decoration:none;
text-align:left;
color:blue;
font-size:14pt;
font-weight:bold;
font-style:normal;
font-family:serif;
line-height:14pt;
}
</STYLE>
<SCRIPT LANGUAGE="JavaScript">
interval = 150;
increment = 1;
canvasColor = "WHITE";
//-->
</SCRIPT>
</HEAD>
<BODY background="img/SfondoAnnunci.gif">
<div align="center"><IMG SRC="blank.gif"
NAME="holdspace" ID="holdspace"
HEIGHT="43" WIDTH="90%"
STYLE="visibility:hidden; position:relative;"> </div>
<IFRAME STYLE="display:none"></IFRAME>

<SCRIPT LANGUAGE="JavaScript1.2">
<!--


var IE4 = (document.all) ? true : false;
var NS4 = (document.layers) ? true : false;

var Gtimer;

var upperPage;
var lowerPage;

var holdingImage = document.images["holdspace"];

var canvasLeft = holdingImage.offsetLeft;
var canvasTop = holdingImage.offsetTop;

var canvasWidth = holdingImage.width;
var canvasHeight = holdingImage.height;

var pageHeight = 0;

var arBody = new Array();

//onload = startCanvas;

window.onresize = redirect;
window.onload = startCanvas;

function redirect() {
location.href = 'annunci.htm';
}

function showMessage() {
upperPage = firstPage;
lowerPage = secondPage;
upperPage.style.pixelTop = 0;
pageHeight = firstPage.clientHeight;
secondPage.style.pixelTop = pageHeight;
firstPage.onmouseover = stopScrolling;
firstPage.onmouseout = scrollPages;
secondPage.onmouseover = stopScrolling;
secondPage.onmouseout = scrollPages;
}

function moveUp() {
upperPage.style.pixelTop -= increment;
lowerPage.style.pixelTop -= increment;
if (lowerPage.style.pixelTop <= 0) rotateThePages();
}

function rotateThePages() {
if (upperPage == firstPage) {
upperPage = secondPage;
lowerPage = firstPage;
}
else {
upperPage = firstPage;
lowerPage = secondPage;
}
lowerPage.style.pixelTop = pageHeight;
}

function makeCanvas() {
var text = '<DIV ID="canvas" STYLE="position:absolute">';
text += '<DIV ID="firstPage" STYLE="position:absolute">' + arBody[0].innerHTML + '</DIV>';
text += '<DIV ID="secondPage" STYLE="position:absolute">' + arBody[0].innerHTML + '</DIV>';
text += '</DIV>';
document.body.insertAdjacentHTML("BeforeEnd", text);
with (canvas.style) {
width = canvasWidth;
height = canvasHeight;
clip = "rect(0 " + canvasWidth + " " + canvasHeight + " 0)";
backgroundColor = canvasColor;
}
canvas.style.pixelLeft = canvasLeft;
canvas.style.pixelTop = canvasTop;
}

function startCanvas() {
if (NS4) return;
document.all.tags("IFRAME").item(0).src = 'annunci.asp';
}

function fillCanvas() {
arBody = document.frames(0).document.all.tags("BODY");
makeCanvas();
showMessage();
scrollPages();
}

function scrollPages() {
Gtimer = setInterval("moveUp()", interval)
}

function stopScrolling() {
clearInterval(Gtimer);
}

//-->
</SCRIPT>
</BODY>
</HTML>

The problem is:
Everything works fine in local (on my Win2K pro with IIS 5) but when I post it on the website it behaves weirdly. The first time the page gets loaded everything works and the scrolling cycles correctly. However, if you hit "refresh" the page will only scroll once and then give an error about some variables or fields of variables being null or not being objects. I highlighted in red the lines where these errors occur most frequently. I do not enclose the error message because it is not always the same. The behavior is, however, the same, and it causes the first scroll to work, but no cycle. I figured it could be a problem with refresh, because when the user resizes the page (which causes a redirection to the page, and I THOUGHT it would be equivalent to a refresh) everything works fine. How can I solve it? Is there a way to detect refresh of the page and make it behave like a redirection?

I will be hugely grateful to whoever can help, since this problem is making me fall behind on the job!

Thx in advance,

Alex Damiani

alex80it
07-03-2003, 09:15 AM
Many many thanks!

Well, it is encouraging to know that it worked for 90% of browsers, but now that I got it to work on the whole of them I'm much happier!
Thanks for pointing out to me that one ought to keep an eye on programming style when he works!
:rolleyes:

Hope to be able to help you in return, sometimes!

Alex