Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Vancouver, WA
    Posts
    233
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Automated Changing Text and Backgrounds

    I wasn't sure what to title this and it won't be easy to put in words.

    What it's about is the banner ads I've created with text because Norton and other software is stopping banner ad graphics from appearing on the page more and more often now. (Actually this whole matter came up because my pages are created entirely with JavaScript and when I put banner ad graphics on them Norton crashed them. So I've reverted to text.)

    Anyway, my question is... is there a way to make a banner with HTML and table code and, obviously, JavaScript, and have the contents change. For example, when the banner first appears it might flash Free Trial a couple times then settle down so as not to be annoying.

    I know you can create timers with JS and so I could call a function at certain times. But the only way I can think to do this would be to re-write the page each time I want the banner to change. And I don't want to re-write the whole page... just the banner.

    I could also do it using Frames and just re-write a single frame containing the banner, but I don't want to divide up the page that way.

    I also don't want to use FLASH.

    What I want is probably either impossible, or done all the time and I just need to be pointed in the right direction.

    Thanks, Peter

  • #2
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    If you know how timers work, this should be quite easy:

    You have, say, a <p> with 'free trial' written in it.
    onload, start your function.
    It changes the text to '' (nothing) after 1 second.
    It then waits another second and changes it back to 'free trial'.
    It repeats that 3 times or as many as you like.

    so:
    Code:
    html:
    
    <p id='banner'>Free Trial</p>
    
    js:
    
    function bannerBlink(){
    
    for(var i=0;i<3;i++){
     timer that times out 1 seconds;
     banner.innerHTML=''; //nothing
     timer that waits 1 second;
     banner.innerHTML='Free Trial';
    }
    }
    or something like that. Does this make sence?
    Shawn

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Vancouver, WA
    Posts
    233
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks very much. Never used "for" before (used "while") but I looked it up and that's easy to undertand. Never used ID before and I can't get it to recognize it... I always get the error message "freeTrial" is undefined.

    Maybe I can't put ID in a table?

    First I tried it here:

    b1+="</td></tr><tr><td align=center valign=top id='freeTrial' class='bannerSubText'>";

    Then as you see it in the full table here inside a <p> as you suggested:

    // Whatever banner
    b1="<tr><td align=center>";
    b1+="<table width=500 bgcolor='#000000' cellpadding=2 cellspacing=0 align=center onClick='top.location.href=\"whatever.html\"' onMouseOver='this.style.cursor=\"pointer\"'><tr><td>";
    b1+="<table width=100% bgcolor='#66ff66' cellpadding=1 cellspacing=0><tr><td>";
    b1+="<table width=100% bgcolor='#000000' cellpadding=1 cellspacing=0><tr><td>";
    b1+="<table width=100% bgcolor='#ccffcc' cellpadding=0 cellspacing=0><tr><td align=center class='bannerText'>";
    b1+="First row of text goes here.";
    b1+="</td></tr><tr><td align=center valign=top class='bannerSubText'>";
    b1+="<p id='freeTrial'>Free trial text goes here.</p>";
    b1+="</td></tr></table></td></tr></table></td></tr></table></td></tr></table>";
    b1+="</td></tr><tr><td height=10></td></tr>"

    As a test I tried putting alert(freeTrial.innerHTML) in a number of places and always got the error message. It's very complex because b1 is just part of a large page. I tried the alert both after b1 was included in the code being assembled, and after the document.write after the page was created. Nothing worked.

    Anyway, I'll sort out this mess another time. But thanks for the great reply, and please let me know if ID can be placed in a table in <td> or wherever.

    Peter

  • #4
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    An id can be placed anywhere. I know what your problem is.
    To be applied, this id has to be loaded on the page. The alert you are doing happens before the page has finished loading, You need to start this blinking thing after the loading has finished. so:

    <body onload='yourfunction()'>

    should work..

    To help you further, I would need to see your code.
    Shawn

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Vancouver, WA
    Posts
    233
    Thanks
    2
    Thanked 0 Times in 0 Posts
    c+="</td></tr></table></td></tr></form></table></td></tr></table>";

    parent.image.document.write(c);
    parent.image.document.close();
    parent.image.focus()}
    </script>

    </head><body onLoad='loaded=true; makeImage()'></body></html>

    This is the end of my code. I finish accumulating the code in c then write it into the visible Frame .image.

    I can't remember why after the document.write I re-create the page with makeImage() -- I think because I need to be sure something has been completed in another Frame so I do the onLoad -- but it's been working for years.

    Thanks so much, Peter

  • #6
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    You need this blinking effect to be the very last thing in your function. But I repeat that to help you more, I would need the code. the COMPLETE code. With everything.
    Shawn

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Vancouver, WA
    Posts
    233
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It's a half a dozen files (it inserts .js files) for a number of frames and thousands of lines of codes. How would I show you?

    Thanks. I'll be on again tomorrow, Peter

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    Vancouver, WA
    Posts
    233
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Shlagish,

    I had one of those moments where you're thinking about something totally different... hadn't thought about this for days... and the problem/solution popped into my mind.

    When I did my alert(freeTrial.innerHTML) test I forgot I was working in frames and needed alert(parent.frameID.freeTrial.innerHTML).

    It worked right away. Now I just need to dig up my old code to time something!

    Thanks so much, Peter

  • #9
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I'm happy it turned out okay
    Shawn

  • #10
    Regular Coder
    Join Date
    Jun 2002
    Location
    Vancouver, WA
    Posts
    233
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I guess I need help with a timer. I searched Google and got so many complex ones. I'm surprised there isn't something simple like pause(500).

    I tried to create something simple but it didn't work:

    setTimeout("pass()",500);
    function pass(){}

    Can you point me in the direction of a simple routing just to pause for some time?

    Thanks again, Peter

  • #11
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    The timeout or interval way is the best - neither is a 'busy' waiting, which means they don't consume clock cycles while waiting.

    Now, what is the code you're trying to run after a delay? If it contains document.write or document.writeln, then that's the problem.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #12
    Regular Coder
    Join Date
    Jun 2002
    Location
    Vancouver, WA
    Posts
    233
    Thanks
    2
    Thanked 0 Times in 0 Posts
    No, it's after the page is all completed. After the page has been displayed on the screen it simply changes the text to make it flash in a banner.

    I have it all working but need to time it to slow the flashing down.

    Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •