简体   繁体   中英

Executing script inserted with innerhtml

I'm using the following code to attempt to execute one of adNetworks banners after an innerhtml has been called

   // container is where you want the ad to be inserted
var container = document.getElementById('sponsor_container2');
var w = document.write;
document.write = function (content) {
    container.innerHTML = content;
    document.write = w;
};
var script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = 'http://go.adversal.com/ttj?id=2609728&size=728x90&promo_sizes=468x60,320x50,300x50,216x36';
document.body.appendChild(script);

However for whatever reason I reason the following message

Resource interpreted as Script but transferred with MIME type text/html: "http://ib.adnxs.com/ttj?id=2609728&size=728x90&promo_sizes=468x60,320x50,300x50,216x36". 

And nothing happens, the above code has worked in the past for previous adNetworks so this is why I'm so dumb founded

This is the script my ad page provided me

<script src="http://go.adversal.com/ttj?id=2609728&size=728x90&promo_sizes=468x60,320x50,300x50,216x36" type="text/javascript"></script>

: document.write() is a function that is used to write to the document, and as you may know, you cannot re-define defined functions in Javascript. document.write()是用于写入文档的函数,并且您可能知道,您不能-在Javascript中定义定义的函数。

You probably just want document.write(w) or something like that.

Hope I could help.

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