简体   繁体   中英

Dynamically replace ad tags

Once and for all I'd like to settle this issue I am dealing with since years. It's quite simple: I have a site, and I have some ads on it. The ads are JavaScript tags from various partners. They are alwaysd hosted on external servers, vary greatly and render all kinds of things: iframes, flash layers, whatever, in various sizes and shapes and so on.

With the site behaving more and more like an application, I'd like to be able to load new ads via JavaScript (and not with a page reload). Simply said, I'd like to document-write a new ad tag on the site. Problem is - and has always been, that the whole web page will then be replaced with the new JS code.

What solutions (other than iframes!) are out there?

Instead of divs for your ad containers, use iframes. You can inject scripts into these frames without upsetting your outer document (since the iframe will have a different document object).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM