Dynamically insert <script> tags in HTML on a Load page

I am trying to dynamically embed a Tweetmeme button using Javascript. I am currently using jQuery throughout the site. Here is the script I'm using. I basically want to iterate over all blog entries with a journal entry class and add the following JavaScript to the end. This Javascript comes straight from tweetmeme.com. This does not work for me, and it has something to do with the code between append (). This is not like the second set of script tags.

<script type="text/javascript"> 
$(document).ready(function() {

$('.journal-entry').each(function(index) {
    $(this).append('<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script>');
   });

});
</script>

Any help is appreciated. Thank.

+1
source share
2 answers

Do not do this.

Embedding <script>HTML content in the DOM is unreliable: it works differently in different browsers, and jQuery will not protect you from the differences.

, innerHTML <script>, <script> , ( jQuery append), script , ( ).

, , , button.js, document.write(). ; , , . A script, document.write(), <script>. script , .

( , , , button.js script - , URL-, escape encodeURIComponent -and missing HTML-escaping. .)

+4

</script> append(...) <script>

. :

$(this).append('<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></'+'script>');
+2

All Articles