Jump to content

Archived

This topic is now archived and is closed to further replies.

Gutspiller

Noobie: Need help to get java to refresh banner code

Recommended Posts

I have knowledge of how javascript works. I was talking in this thread: [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=90049\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=90049[/a] and it seems that javascript is going to work the best for me. Figured I would more pinpoint my request in this forum.

I have the banner code from my ad company and the code stays the same. It's not like images and hyperlinks, but the code that grabs the info from the ad company.

Is all I need the javascript code that will refresh my ad code every 30 seconds without refreshing the rest of the page. Can somebody please help me out on how I would set this up so that it would work?

I would really appreciate any help I can get. I'm not making much money and banners in iframes grab the keyboard control focus away from my onine arcade when people play the games in the window.

Please help.

Share this post


Link to post
Share on other sites
Hi there,

After few readings, your old post, that one & few searches, here is how I would operate,

On body load, the first banner could be set into a file called 'banner.html', by ex. The code for this file can be about:
[code]
<html>
<body>
<H1 id="banner_contents" align=center>Hello</H1>
<img id="ad" src="image1.jpg">
<a id="url" href="">http://www.asite.com/</a>
</body>
</html>
[/code]
I've read the tips written by Vorotaev for the javascript part & made few changes: the main file should change and resfresh the banner part with this kind of code:
[code]
<html>
<head>
<script>
// Produce two new arrays to hold the information.
var banners = new Array();
var links = new Array();
var text = new Array();

var i = 0;

// The banners array holds the URLs of 4 banners.
banners[0] = "image1.jpg";
banners[1] = "image2.jpg";
banners[2] = "image3.jpg";
banners[3] = "image4.jpg";

// The links array holds the matching links for the banners array.
links[0] = "http://www.asite.com/";
links[1] = "http://www.anothersite.com/";
links[2] = "http://www.notasite.com/";
links[3] = "http://www.asdfghjkl.com/";

// Some text to test,,
text[0] = "Hello";
text[1] = "the";
text[2] = "world";
text[3] = ":o)";

function myfunction()
{
    // Update the text
    document.getElementById("frame1").contentWindow.document.getElementById("banner_contents").innerHTML=text[i];

    // Update the banner image URL.
    document.getElementById("frame1").contentWindow.document.getElementById('ad').src=banners[i];

    // Update the site the banner links to.
    document.getElementById("frame1").contentWindow.document.getElementById('url').href=links[i];
    document.getElementById("frame1").contentWindow.document.getElementById('url').innerHTML=links[i];

    // Increment i so a different banner/link shows next time.
    i++;

    // If the variable i gets larger than the largest number in our arrays, set it back to 0 (reset the banner rotation).
    if(i > 3) {
        i = 0;
    }

// removing the focus on the frame1
document.getElementById("frame1").blur();

}

// set the time interval there
setInterval("myfunction()",1800);

</script>

</head>

<body>
<IFRAME Id="frame1" SRC="banner.html" WIDTH=950 HEIGHT=100>If you can see this, your browser doesn't understand IFRAME.</IFRAME>

<br>

<div align=center>
hmm,... still focusing,....? :)
</div>

<br>
</body>
</html>
[/code]
I've not tested it completely using flash elements, so, not fully sure it works for you,,

Hoping it helps,

l8tr,,

Share this post


Link to post
Share on other sites
This looks close to what I need, but I don't have images, links and text. I have one chunk of code supplied by an ad company. That code does the rotating. All I need is for that same chunk of code to refresh. How would I modify the code you provided so that it would work with one peice of code, instead of multiple links, images and text?

Thanks for your help!

Share this post


Link to post
Share on other sites
Ok,, let's try that one,,
html part:
[code]
<html>
<head>
<title>refreshing a div content,,</title>
</head>
<body>
here is my dynamic div,,
<div id="banner" align="center" style="font-size:15px;"></div>

<script src="the_code_to_reload.js"></script>

<script>
// we call the function on body load
myfunction();
// we set an interval in milliseconds (10000=10 sec)
var interval = 1000;
// and we assign the function to be refreshed with the interval
setInterval("myfunction()",interval);
</script>
and it is refreshed,, each <span id="inter"></span>
<script>
  Number.prototype.round = function(d) {
    return (Math.round(this*Math.pow(10,d))/Math.pow(10,d));
  }
document.getElementById('inter').innerHTML=(interval/1000).round(2)+" secs";
</script>
</body>
</html>
[/code]
& the 'the_code_to_reload.js' could be about:
[code]
//in this file, put the code you want to be refreshed

// for test, we take the alphabet as example,
Alphabet  ="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var i=0;

function myfunction()
{
if (i==26)
    {
    i=0;
    }
Letter=Alphabet.substr(i,1);
document.getElementById('banner').innerHTML=Letter;
i=i+1;
}
[/code]
Hoping it helps,... if not, please be more clear in your explain/what you need,, my english s** sometime,... :s

l8tr,,

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.