How to insert javascript code in iframe tag

iframe, javascript, jquery

Solution

Scripts like that appear to break when `</script>` is included in the string. A workaround to that could be to add the elements through dom manipulation:

iframe = $('<iframe>');

var script   = document.createElement("script");
script.type  = "text/javascript";
script.src   = "http://www.abc/static/st.v2.js"; // Or:
script.text  = "Your code here!"

iframe[0].appendChild(script);
iframe.appendTo('#subscribr'))

Problem

I am doing like this but not working:- I am trying to insert the pixel in iframe and then append it to the body. ``` jQuery('#subscribr').append('<iframe> <script language="javascript" src="http://www.abc/static/st.v2.js"></script> <script language="javascript"> var ef_event_type="transaction"; var ef_transaction_properties = "ev_ProductViews=1"; /* * Do not modify below this line */ var ef_segment = ""; var ef_search_segment = ""; var ef_userid="xxxx"; var ef_pixel_host="pixel.abc.net"; var ef_fb_is_app = 0; effp(); </script> </iframe>'); enter code here ```

Original source