Hi Noah! Thanks so much for the quick and informative reply, I really
appreciate it.
Yikes! I can't believe I hadn't seen that before! Thanks for linkage. :D
> Yes, the code I posted is using WC2.
Awesome. Bookmarking that gist now. Thanks for posting it. :)
> You definitely need to be careful not to run multiple captures at
> once. document.write normally blocks the loading of an HTML document
> (which is one or many reasons to hate it). writeCapture lets you load
> it asynchronously, but unfortunately the nature of how document.write
> works means that trying to load more than one script at a time will
> cause all kinds of problems. If you're doing that, I can definitely
> see you having issues, especially cross browser.
Thanks for the details and clarification.
You know, I never really knew how much document.write sucked until I
needed to get OpenX ads to work in a responsive layout... My first
thought was to take the OpenX ad tag calls and put them in a variable
and use those variables when needed... Um, yah, that didn't work so
well (each OpenX ad call has one, if not more nested,
document.writes).
I had two goals in mind when working with your code (and the
onMediaQuery script):
1. Put ad calls at bottom of page so that the rest of the page loads
before any ad stuff happens.
2. Based on viewport size, call new ad sizes to replace existing ad
sizes (i.e. a Leaderboard ain't going to fit when the viewport is less
than 728px wide).
Note: Both of the above are very counter intuitive to how OpenX ads
are supposed to be setup.
So, I think I've come close to finding a solution (as shown in my
demos) and WriteCapture is spectacular! I think it all boils down to
OpenX needing to change how they serve ads (i.e. nested
document.writes, like, wtf?)
> If you are loading a single script at a time and still have problems,
> please raise an issue (with a jsbin or jsfiddle example please). There
> are unfortunately many browser bugs and that sort of thing that Ad
> servers (stupidly) tend to rely on.
I have a demo here:
<
http://registerguard.github.com/ads-on-demand/demo/demo2.html>
All the ad code is at the bottom of the page... When the page first
loads, then line #157 (right before the closing script tag) calls its
first writeCapture(). From there, the callback() calls
MQ.init(queries) (that's the onMediaQuery plugin) which then checks
viewport size and requests the appropriate ad using an additional
writeCapture().
Question: If I call a writeCapture() in the callback method of another
writeCapture(), would you consider that "load(ing) more than one
script at a time"?
Anyway, as you can see on that demo page, I've listed the browsers
that are buggy and/or fail; I think there's bugs for many reasons...
To name a few:
1. I'm using multiples JS plugins to do something that should just be
done, IMHO, on the ad server side.
2. OpenX code base is using oldschool techniques.
3. The buggy/fail browsers are old and suck anyway. ;)
> If there is a need for loading multiple scripts at once, I'll look
> into building out an official plugin to manage that.
Oh, I'd say, not for me... I don't know if there are many other people
out there trying to do this (i.e. load ads on demand based on viewport
size). Thanks for the offer though, that's very kind of you. :)
Thanks again for your help! I really appreciate it.
Have a nice day,
Cheers,
Micky