PDA

View Full Version : cross browser marquee



habman0
12-01-2005, 05:55 AM
I am using php to dynamically create the content that I want the marquee to display and all is working fine.

What I would like to do is refresh/reload the page once the marquee scrolls through its entire contents once. Why the refresh? Well the information that the marquee is to display updates frequently and I would like display the most up to date information and a refresh will accomplish this nicely.

Also a timed refresh won't suffice since the length of the marquee changes each time it is reloaded.

Here is my marquee (http://www.habman.com/mfl/scroller5.php?leagueid=67320&family=Comic%20Sans%20MS&size=12&bgcolor=CCCCCC&fontcolor=008000&speed=2&shownext=no&top=no).

jscheuer1
12-01-2005, 07:56 AM
If you are reloading the page, any forms data will be lost. This idea would best be used in a frame or iframe on your page that contains only the marquee. Any speed set by the user will revert to the default configured speed on reload. That said, here's what to do:

First find this function and change 'false' to 'true' as indicated in red:


function doit(){
if (window.location.reload)
window.location.reload( true );
else if (window.location.replace)
window.location.replace(unescape(location.href))
else
window.location.href=unescape(location.href)
}
Then find this function:


function scrollmarquee(){
if (iedom){
var c1=(direction=='reverse')? (parseInt(cross_marquee.style.left)<parseInt(marqueewidth)) : (parseInt(cross_marquee.style.left)>(actualwidth*(-1)-18));
if (c1)
(direction=='reverse')? cross_marquee.style.left=parseInt(cross_marquee.style.left)+copyspeed+"px" : cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"
else{
if (alternate)
altM();
(direction=='reverse')? cross_marquee.style.left=8-actualwidth+"px" : cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
}
}
else if (document.layers){
var c1=(direction=='reverse')? (ns_marquee.left<parseInt(marqueewidth)) : (ns_marquee.left>(actualwidth*(-1)-18))
if (c1)
(direction=='reverse')? ns_marquee.left+=copyspeed : ns_marquee.left-=copyspeed
else{
if (alternate)
altM();
(direction=='reverse')? ns_marquee.left=8-actualwidth : ns_marquee.left=parseInt(marqueewidth)+8
}
}
}

Make it look like so:


function scrollmarquee(){
if (iedom){
var c1=(direction=='reverse')? (parseInt(cross_marquee.style.left)<parseInt(marqueewidth)) : (parseInt(cross_marquee.style.left)>(actualwidth*(-1)-18));
if (c1)
(direction=='reverse')? cross_marquee.style.left=parseInt(cross_marquee.style.left)+copyspeed+"px" : cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"
else{
doit();
}
}
else if (document.layers){
var c1=(direction=='reverse')? (ns_marquee.left<parseInt(marqueewidth)) : (ns_marquee.left>(actualwidth*(-1)-18))
if (c1)
(direction=='reverse')? ns_marquee.left+=copyspeed : ns_marquee.left-=copyspeed
else{
doit();
}
}
}

jscheuer1
12-01-2005, 08:20 AM
If you want to preserve the user's configured speed from one refresh to the next, add this to doit():


function doit(){
document.cookie='speed='+copyspeed+'endSpeed'
if (window.location.reload)
window.location.reload( true );
else if (window.location.replace)
window.location.replace(unescape(location.href))
else
window.location.href=unescape(location.href)
}

and this to just below 'NO NEED TO EDIT BELOW THIS LINE':


////NO NEED TO EDIT BELOW THIS LINE////////////
marqueespeed=document.cookie.indexOf('endSpeed')==-1? marqueespeed : parseInt(document.cookie.substr(document.cookie.indexOf('speed=')+6))
marqueecontent='<nobr>'+marqueecontent+'</nobr>'

habman0
12-02-2005, 11:22 PM
Thank you Thank you Thank you John. The refresh worked like a charm.

Just one thing about the cookie however.

The cookie remembers its speed upon a page refresh when the page is open in it's own browser however when the scroller is in an iframe then it goes back to it's original speed upon a refresh. BTW I am using the ticker in an iframe.

Is there a special way to implement cookies in an iframe?

Thanks for any help.

jscheuer1
12-03-2005, 04:40 AM
I'm still learning about cookies. I imagine that prefixing 'document' with with 'parent.' would do the trick. As it appears that the cookie is being written for the parent document already, only prefixes in the read call may need to be added. You can play with it and see, try (scroll the code block, it adds three prefixes):


////NO NEED TO EDIT BELOW THIS LINE////////////
marqueespeed=parent.document.cookie.indexOf('endSpeed')==-1? marqueespeed : parseInt(parent.document.cookie.substr(parent.document.cookie.indexOf('speed=')+6))
marqueecontent='<nobr>'+marqueecontent+'</nobr>'

If that doesn't 'get it' try this (in addition to the above) as well:


function doit(){
parent.document.cookie='speed='+copyspeed+'endSpeed'
if (window.location.reload)
window.location.reload( true );
else if (window.location.replace)
window.location.replace(unescape(location.href))
else
window.location.href=unescape(location.href)
}

jscheuer1
12-03-2005, 05:09 AM
I'm not so sure about that. I think the problem may be my cookie syntax. In a local demo here, it works fine in the iframe without any prefixes. There may be something about your server that is preventing the cookies when the page is live. Or, more likely my cookie code isn't ready for prime time yet. What works locally sometimes does not work live. I'll get back to you on that. It could also be an error in your implementation, or with the use of PHP interfering.

jscheuer1
12-03-2005, 05:22 AM
OK, I just tested it live. The cookie works. There could be several reasons why you are not seeing it work. Your browser could have cookies disabled for the domain you put it on. If the PHP is rewriting the page, it may no longer recognize its own cookie (if that is the case, switching them all to the parent may solve this). Can you get it working locally in an iframe using the cookie?

jscheuer1
12-03-2005, 05:44 AM
The only speed bug I can see is where you mouseover a pause of the scroller, then out to resume before it has reloaded. If you do that, it will revert to the default or set marqueespeed. To avoid that, what is needed is to change this bit of code:


write('<div style="position:absolute;width:'+marqueewidth+';height:'+marqueeheight+';background-color:'+marqueebgcolor+'" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')

to:


write('<div style="position:absolute;width:'+marqueewidth+';height:'+marqueeheight+';background-color:'+marqueebgcolor+'" onMouseover="marqueespeed=copyspeed;copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')

habman0
12-04-2005, 07:04 AM
Hi John Thanks for all your work on this.

Can you show me your live page so that I can get some idea where I am going wrong.

Also one other issue. The "refresh" after one scroll, the thing that I thought was working, only works in IE and not in Firefox. In firefox it just keeps trying to reload itself but never loads. Is there something that I did wrong? If not then can how can I get it to work in firefox.


Here is my marquee with refresh only (http://www.habman.com/mfl/scroller5.php?leagueid=67320&family=Comic%20Sans%20MS&size=12&bgcolor=CCCCCC&fontcolor=008000&speed=2&shownext=no&top=no) and no cookies.

Thanks again for all your help.



EDITED TO ADD:

I got the cookie working in an Iframe when both the iframe and main frame are on the same domain. Check it out here (http://www.habman.com/mfl/scrollerWMframe.html)

However the cookie is not working in an iframe when both the iframe and main frame are on different domains. Check it out here (http://home.cogeco.ca/~sph22/scrollerWMframe.html)

jscheuer1
12-04-2005, 08:44 AM
Here is a demo of it in an iframe with the all code for the marquee and cookie on the page inside the iframe:

http://home.comcast.net/~jscheuer1/side/iframedemo.htm

To make things clearer, as I look over my posts in this thread, I should repeat that in the end, I could find nothing wrong with my original cookie code. That the only problem seemed to be with that line of code from my last post in this thread. I've fixed that in my online demo.

It would actually be more instructive to me if you were to put up a demo of it in an iframe, with the original reload code + the original cookie code I supplied, so I could test if it is misbehaving in the way I suspect or if there is something else at work. Or if you want to jump ahead and see if the code in my new demo works for you as well, that might be better. If it works for you, great! If not, at least we will have the latest code to proceed from in debugging. I am concerned that there might be factors beyond our control at work related to PHP or your server in general but, we can't tell about that yet.

habman0
12-04-2005, 02:13 PM
Hmm. The demo page is not working for me meaning the cookie does not set itself. I tried deleting all my cookies and rebooting but still no luck.

Also I tried your code in IE and Firefox and the refresh only works in IE which is what I am experiencing with my code as well. If you have firefox installed can you check to see if it refreshes itself in firefox.

Thanks.

jscheuer1
12-04-2005, 07:24 PM
I've checked in FF, IE and Opera. There is a problem! I've taken the demo down for now. All the browsers worked locally, so when I uploaded it, I only checked in IE. Big mistake. I've tried a few things that might solve the problem but, no luck so far. I'll let you know if I get something cross browser. Incidentally the reload and cookie were working fine in the iframe, live in IE, for whatever that is worth. Not much, I know, but just to compare notes.

habman0
12-05-2005, 05:32 AM
Hi John,

Just wanted to let you know that my cookie is working fine in firefox but not in IE. :confused: The exact opposite of the refresh script which works fine in IE but not firefox. UGGHH.

I must have to change a setting in IE to let the cookie pass. Don't know where to do this though. Any suggestions?

EDITED TO ADD:

My security setting under the Privacy tab was set to medium by changing it to low it worked in IE. Thanks for all your help could not have gotten this far without it. Let me know if you can figure out a fix for the refresh. I've tried a couple of things but neither has worked.