Re: cloneNode, Ad Rotation, caching, iframes - issue issues issuess

"John M. Hann" <[email protected]> Thu, 30 Mar 2006 15:46:32 -0000
Newsgroups gmane.comp.web.dom.wdf
Message-ID <[email protected]>
Btw, Mandy, this method is common in CGI.  The trick is to render one
or more "frames" in the background and show them as needed.  Copying
is too computationally expensive in CGI (and problematic in browsers,
it seems!).  Memory to store the multiple frames in CGI is relatively
cheap.  So, just load up as many frames as possible and flip thought
them as fast as possible.  (That's why video cards with lots of RAM
are good for gamers.)

In your case, you only need two DIVs if the user's actions that
trigger the ad change are not very fast.  If this is not the case,
just alter the algorithm slightly to rotate through 3 or more DIVs.

Another note: depending on your HTML, you may want to use a style
attribute of visibility, opacity, and/or zIndex rather than display. 
It doesn't matter how you show/hide the ads, as long as you aren't
copying / cloning...

Let me know if I need to write some code or explain anything...

Regards,

-- John

--- In [email protected], "John M. Hann" <john.hann@...> wrote:
>
> Hey Mandy,
> 
> If you always plan to have only one ad (or a few) in the queue, this is
> an easy problem to solve.  That is, unless I am missing something.
> 
> Try looking at it this way instead:
> 
>     1. Place centralContent and nextAd DIVs in the same container /
> parent on the page and give them the exact same CSS attributes (except
> add a declaration making nextAd's display: none -- or do this in
> Javascript).
>     2. in displayAd() (or in some sub routines) keep a counter that
> tracks each time displayAd() is called.
> 
> 
>     1. If the counter is odd (counter % 2 == 1), display the nextAd DIV:
> document.getElementById('nextAd').style.display = 'block';
> document.getElementById('centralContent').style.display = 'none';
>     2. If it's even, do the opposite:
> document.getElementById('nextAd').style.display = 'none';
> document.getElementById('centralContent').style.display = 'block';
> 
>     3. Retrieve the next ad into the DIV that is not showing.
> 
> You'll probably want to rename the DIVs to something more meaningful and
> initialize the counter somewhere - or just use this: counter = (counter
> || 0) + 1 .  Pre-resolving the document.getElementById() calls is more
> efficient, too.
> 
> No caching issues.  No cloning or copying.
> 
> Does this work for you?
> 
> -- John
> 
> http://e-numera.com/ <http://e-numera.com/>
> http://ajax-web2.com/ <http://ajax-web2.com/>
> 
> 
> 
> --- In [email protected], "Maninder, Singh" <mandiv@> wrote:
> >
> > Hi,
> >
> > I need some guidance/expert views on an ad rotation script that I am
> writing.
> >
> > The idea is to build an ad queue (with only 1 ad in it) and caching of
> ads.
> >
> > So, by default on the page (centre space), I will show some static
> gif.
> > As soon as the page loads, I'll fire a request to get an ad and push
> it into my queue.
> > Next time any user action takes place (assuming he doesnt leave the
> page) I'll use the ad downloaded in the queue and display it
> > in the centre space and fire another request to get the next ad and
> push it to queue.
> >
> > Since ads are got from a 3rd party partner this will speed up the ad
> display process as they would be served from the cache
> > and when requested...
> >
> > However, I am facing an issue with it (script attached below).
> >
> > I declare 2 divs on my page - centralContent & nextAd.
> >
> > centralContent is where the ad should be displayed and nextAd div is
> where I am downloading the ad (queue/cache).
> >
> > So, I fire getNewAd() first that gets the new ad and places it's
> results in the nextAd div.
> > It also clones it and keeps it for further use.
> >
> > Then when user clicks on get next ad, displayAd() is called, where I
> clear the centralContent & nextAd divs, use the cloned result
> > and write it to centralContent (expecting it be quicker since it is
> served from cache) and fire getNewAd() again.
> >
> > But, the problem is that when getTag() is called, it writes an iframe
> to the page that calls the partner url that writes another\
> > 3 iframes in that iframe with 3 ads. I don't think cloneNode is able
> to capture that information as it's on another domain - right?
> >
> > So, how can I work around this problem?
> >
> > Any thoughts?
> >
> > Thanks,
> > Mandy.
> >
> > Ad Rotation<br />
> > <div id='centralContent'>THE AD FROM THE QUEUE <br/> WILL GO
> HERE</div><br /><br /><br />
> > <div id='nextAd'>NEXT AD IN THE QUEUE <br />WILL APPEAR HERE</div><br
> /><br /><br />
> > <*cript>
> >
> > adContainer = "";
> >
> > document.write = function(text){
> > adContainer = text;
> > };
> >
> > function refreshOriginalAdContainer() {
> > document.getElementById('centralContent').innerHTML = '';
> > }
> >
> > function refreshNextAdContainer() {
> > document.getElementById('nextAd').innerHTML = '';
> > }
> >
> > function appendToOrginal() {
> > document.getElementById('centralContent').appendChild(tempAd);
> > }
> >
> > function cloneExistingAd() {
> > try {
> > temp   = document.getElementById('nextAd').cloneNode(true);
> > tempAd = temp.childNodes[0];
> > }
> > catch(e) {
> > alert(e);
> > }
> > }
> >
> > function getNewAd() {
> > try {
> > //this will get the ad from the server it's not defined on this page
> > getTag('WEBMAIL','TOPCENTER','LEADERBOARD','728','90');
> > document.getElementById('nextAd').innerHTML = adContainer;
> > cloneExistingAd();
> > }
> > catch(e) {
> > alert(e);
> > }
> > }
> >
> > function displayAd() {
> > try {
> > refreshOriginalAdContainer();
> > refreshNextAdContainer();
> > appendToOrginal();
> > getNewAd();
> > }
> > catch(e) {
> > alert(e);
> > }
> > }
> >
> > getNewAd();
> >
> > </*cript>
> >
> > <a href=# OnClick="displayAd(); return false;">Get New Ad</a> <br
> /><br />
> >
> 
> 
> 
> [Non-text portions of this message have been removed]
>





Unsubscribe
[email protected]

List info
http://www.quirksmode.org/dom/list.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/wdf-dom/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/