Results 1 to 3 of 3

Thread: DHTML Ad Box

  1. #1
    Join Date
    Apr 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow DHTML Ad Box

    Hi all,

    Can sombody tell me how to setup the script that the DHTML box ONLY 1 time for 5sec appear.
    If the user reload or come back to the main page within 5min the box does not appear again. After 5min the box have to appear again.

    http://www.dynamicdrive.com/dynamicindex11/dhtmlad.htm

    I've tried with changing of the following X value but no success :
    adTime=7;
    chanceAd=X;

    Any ideas or suggestions..?

    Thanks in advance
    JOML

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That value (chanceAd=X;) only represents how likely the ad is to show. It has nothing to do with timing. Each page load, the ad will have a one in X chance of appearing. If it is set to 1, that is one chance in one, or all the time. If it is set to 2, the chance that the ad will show is 50% but, this is reset each page load, so the ad could appear several page loads in a row or not appear several in a row - over a long period of repeated page loads, it will appear about half of the time.

    What you are asking for could be done using a cookie or cookies, perhaps combined with an onpage timer and/or flag. All that would depend upon just what you would want to have happen. The easiest is just to set one cookie on page unload. This cookie could be set to expire after five minutes and be set not to be reset unless it had expired. If the page were simply reloaded though (without navigating away first), even after the cookie expired, the ad would not be shown again, however, if the page were navigated away from and, before the page were returned to, the cookie expired, then the ad would show. A special circumstance would arise if the page were returned to before the cookie expired but reloaded after expiration, in this case, no ad would show.

    Here is that version of things:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    
    #sponsorAdDiv {position:absolute; height:1; width:1px; top:0; left:0;}
    
    </style>
    
    <script type="text/javascript">
    
    /******************************************
    * DHTML Ad Box (By Matt Gabbert at http://www.nolag.com)
    * Visit http://www.dynamicdrive.com/ for full script
    * This notice must stay intact for use
    ******************************************/
    
    adTime=10;  // seconds ad reminder is shown
    chanceAd=1; // ad will be shown 1 in X times (put 1 for everytime)
    var respite=5 // set to number of minutes add will not be shown under any circumstances
    
    var ns=(document.layers);
    var ie=(document.all);
    var w3=(document.getElementById && !ie);
    var calunit=ns? "" : "px"
    adCount=0;
    function initAd(){
    if (readCookie('adtimer')=='adtimer')
    return;
    	if(!ns && !ie && !w3) return;
    	if(ie)		adDiv=eval('document.all.sponsorAdDiv.style');
    	else if(ns)	adDiv=eval('document.layers["sponsorAdDiv"]');
    	else if(w3)	adDiv=eval('document.getElementById("sponsorAdDiv").style');
    	randAd=Math.ceil(Math.random()*chanceAd);
            if (ie||w3)
            adDiv.visibility="visible";
            else
            adDiv.visibility ="show";
    	if(randAd==1) showAd();
    }
    function showAd(){
    if(adCount<adTime*10){adCount+=1;
    	if (ie){documentWidth  =truebody().offsetWidth/2+truebody().scrollLeft-20;
    	documentHeight =truebody().offsetHeight/2+truebody().scrollTop-20;}	
    	else if (ns){documentWidth=window.innerWidth/2+window.pageXOffset-20;
    	documentHeight=window.innerHeight/2+window.pageYOffset-20;} 
    	else if (w3){documentWidth=self.innerWidth/2+window.pageXOffset-20;
    	documentHeight=self.innerHeight/2+window.pageYOffset-20;} 
    	adDiv.left=documentWidth-200+calunit;adDiv.top =documentHeight-200+calunit;
    	setTimeout("showAd()",100);}else closeAd();
    }
    function closeAd(){
    if (ie||w3)
    adDiv.display="none";
    else
    adDiv.visibility ="hide";
    }
    
    function truebody(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    }
    
    function createCookie(name,value,minutes)
    {
    if (minutes)
    {
    var date = new Date();
    date.setTime(date.getTime()+(minutes*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
    }
    
    function readCookie(name)
    {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++)
    {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
    }
    
    onload=initAd;
    
    onunload=function(){
    if (readCookie('adtimer')=='adtimer')
    return;
    createCookie('adtimer', 'adtimer', respite)
    }
    
    </script>
    </head>
    <body>
    <img src="../side/1st.jpg">
    <div id="sponsorAdDiv" style="visibility:hidden">
    <table width="450px" height="350px" bgcolor="#008000"><tr><td>
    <table width="445px" height="345px" bgcolor="#F0FFF0"><tr><td align="center" valign="middle">
    
    <!--*****EDIT THIS MESSAGE*****-->
    <A HREF="http://www.amazon.com/exec/obidos/redirect-home/wa0c?tag-id=wa0c&placement=home-btn-100x70.gif&site=amazon">
    <IMG SRC="http://www.associmg.com/assoc/us/home-btn-100x70.gif?tag-id=wa0c"></A><p><b>Please take time to show your support<br>
    for this site by visiting one<br>
    of our sponsors during this<br> brief intermission.</b>
    </p>
    <p><A HREF="http://www.amazon.com/exec/obidos/redirect-home/wa0c?tag-id=wa0c&placement=home-logo-130x60b.gif&site=amazon">
    <IMG SRC="http://www.associmg.com/assoc/us/home-logo-130x60b.gif?tag-id=wa0c"></A></p>
    <p>(This announcement will close shortly)
    <br>
    
    <!--*****EDIT THE ABOVE MESSAGE*****-->
    </td></tr></table></td></tr></table>
    </div>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Great

    Thanks a lot.

    This is what I've searched..

Bookmarks

Posting Permissions

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