开发者

Rendering ads in an iFrame then moving them to the main window

开发者 https://www.devze.com 2023-03-14 03:27 出处:网络
I have a set of ads that are written out by document.write because that is the only thing that the adserver will do.

I have a set of ads that are written out by document.write because that is the only thing that the adserver will do.

I have seen other sites reload ads on the page if the user sits there for a while (something I may want to do in the future). So I was playing with loading the ads in an iFrame, then moving them out into the main window afterwards. This seemed to work quite well, until it served up a google ad which is itself in an iframe within the iframe. Is it possible to pull them out properly / move google ads around the page at all?

This is what I have currently, and it works for everything but iframed ads within the iframe.

$().ready(function(){
    $('#iframe').load(function(){
     开发者_如何转开发   var middle_ad_contents = $('#iframe').contents().find('#middle_ad').html();
        $('#ad_middle').html(middle_ad_contents);
    });
});

[edit]

Upon further investigation... it looks like reloading google ads may be against the terms of service, perhaps I shouldn't do this?

[edit 2]

Reloading the whole page is not really an option (and kind of a dick move).

The point was to perhaps rotate the ads, but more to stop them from blocking the pageload because adserver X, which is being served through adserver Y which is being served through adserver Z is slow/not responding. The iframe seemed like the best solution because then I can delay the document.writes which are 2 or three levels deep until the end of the page without them wiping out the whole page as document.write after pageload === document.replaceTheWholeDOM. There is also the perhaps the option of monetizing ajaxy/other iframed (shudder) content with this method.


The best way to go about this is probably using a document.write replacement. There are several to choose from, but here's one: https://github.com/eligrey/async-document-write

This will replace the global document.write function with one that can be used even after the page has loaded.


Not only may it be against the terms of service, but it is also lowering the value of the ads to the advertiser and creating a clunky element in UI.

Think about it from a UI standpoint...you're on the site, concentrating on something, then everything flashes. Your attention goes from what you were concentrating to to figuring out what just happened. Never mind, just a banner flip. Next.....now, where was I?

For the advertiser, what if you notice the ad and are about to click on it and BOOM, it changes. Now what, can you go back? If not, you just lost revenue. Users spend seconds on many pages, so unless you've got an incredibly "sticky" website, how much exposure is the advertiser really going to get? Remember, Google rewards AdWord sites for clickthroughs, not based on volume shown, which can actually hurt your CTR.

If you're determined to make this happen, I think I would consider attacking it by having the ad server post directly as it's intended into the dom, then use a javascript-based timer to asynchronously ping the adserver and again tell it to redraw the desired div. I would avoid iFrames like the plague because they're just not friendly in this age of simple Dom manipulation.

Or, you could just take the MSNBC approach and reload the entire page every X minutes. It's a horrible UI pattern, but it would achieve your goal and likely bend (but not break) TOS.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号