Reputation: 245
I need to create script tag and javascript code dynamically.
<script>
alert(0);
alert(1);
</script>
Supposedly, I want to create the script above.
var fileref=document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref[(fileref.innerText===undefined?"textContent":"innerText")] = "<script>alert(0);alert(1);</script>";
How do I mimic the line change (i.e. after alerts there are line changes)? I've tried \n but it doesn't work (br doesn't work either).
You may say it makes no difference, but I must make the line change because I'm trying to use LinkedIn API which provides a unique js implementation that require the line change.
Upvotes: 1
Views: 204
Reputation: 10906
try something like this,Fiddle
var fileref=document.createElement('script');
fileref.type = 'text/javascript';
var code = 'alert(0);alert(1);';
fileref.appendChild(document.createTextNode(code));
document.body.appendChild(fileref);
Upvotes: 0