I’m building a small advertisement system for my website so that I can just add new ads in the database. Most ads consists of images and I will just write an image as innerhtml to a div. This works fine.
However, some ads consists of a script tag only that should be placed where the ad is wanted. Since I have to do this dynamically from either code behind in .NET or from an ajax call, I have some problems with this.
Just setting a innerhtml of a div like this:
<div id="asdf" runat="server">
<script type="text/javascript" src="xxxxx"></script>
</div>
… won’t work since it won’t get executed. No matter if i set it in the code behind on page load, or set with an ajax call.
I might be able to call eval() somehow, but this doesn’t guarantee the script will be placed exactly where i want it to be if I got it right.
Any ideas? This can’t be a new problem, many advertising networks has script tags instead of images and such.
Edit: The javascript file is located on another domain. Everything works if i set the src attribute to a local file containing only an alert! Can’t you make this happen across domains?
You can try this: