My sample php $advert variable as follows;
<script src="http://ad.example.com/scripts/rp.js" type="text/javascript"></script><script src="http://ad.example.com/scripts/rp.js" type="text/javascript"></script>
<script type="text/javascript">
document.write("<"+"script src='http://ad.example.com/rpgetad.ashx?tt=t_&ciid=9775202&rnd="+Math.random()%99999999+"'></"+"script>");
</script>
I want to create js variable with it.
var advert = "<?php echo rawurlencode($advert); ?>";
then i want to decode and append it to specified div and execute it.
var content = decodeURIComponent(advert);
document.getElementById("mydiv").innerHTML = content;
But when i try it doesn't work.
I also tried php's json_encode() and $('<div/>').html(contents).text() decode methods.
I need to do this with javascript if it is posible.
I am caching html responses. Advertising codes from partners are changing every day. So i dont want to destroy page's cache every time. I am generating seperated js file with php to do that.
.innerHTML. You need to usedocument.createElement("script");