简体   繁体   中英

How to execute and append a script tag to the html element using jquery

I have following script tag

<script src="http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=rsb&c=28&pli=3326580&PluID=0&w=728&h=90&ord=|RANDOM|&ncu=$$|CLICK|$$"></script>
<noscript>
    <a href="|CLICK|http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=brd&FlightID=3326580&Page=&PluID=0&Pos=4688" target="_blank">
        <img src="http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=bsr&FlightID=3326580&Page=&PluID=0&Pos=4688" border=0 width=728 height=90>
    </a>
</noscript>

This is executing when, I am simply adding to a html body segments.

But its not executing if I am adding this tag to a html element dynamically with jquery.

I also tried to convert it to dom using jQuery('') before appending to the html element.

Please see my jQuery code which, I am doing to execute this.

var testUrl = $('<script src="http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=rsb&c=28&pli=3326580&PluID=0&w=728&h=90&ord=|RANDOM|&ncu=$$|CLICK|$$"></script><noscript><a href="|CLICK|http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=brd&FlightID=3326580&Page=&PluID=0&Pos=4688" target="_blank"><img src="http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=bsr&FlightID=3326580&Page=&PluID=0&Pos=4688" border=0 width=728 height=90></a></noscript>');
$('#previewImgDiv').html(testUrl);

Can anyone please help me out?

您可以使用postscribe来做到这一点。那是专门用于异步编写javascript的

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