I am trying to insert a script at a particular position in HTML.
The code:
<script type="text/javascript">
function createElem() {
var _rf = escape(document.referrer);
var _lc = escape(window.location);
var _url = 'http://advertiser.vizury.com/campaign/showad.php?width=470&height=160&publisher_client_id=90&force_adv_id=VIZADV91&loc=' + _lc + '&rfr=' + _rf;
var _dm = document.getElementById('vplm');
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = _url;
_dm.parentNode.replaceChild(s, _dm);
}
</script>
<ul>
<li>sddfj</li>
<li>
<img id="vplm" onload="createElem();" src="http://i.imgur.com/YKABvxr.gif">
</li>
<li>aaaa</li>
</ul>
What it is doing is overwriting the whole page and showing just the final content of the injected script.
When I try to create this script tag via appendChild/replaceChild
, the script gets created, but it does not execute.