Wednesday, 21 August 2013

convert blocks from text/plain to text/javascript and execute it

convert blocks from text/plain to text/javascript and execute it

my problem is as follow. I have a multiple script blocks that contain
javascript code type of text/plain. So my question is is there any script
that i can dynamically convert them from text/plain to text/javascript
type and execute its content ? The problem i'm having is the place of
execution, because scripts contain document.write so the output is
appended in the end of the html not on the location of the script itself.
eg: let's say something like this
<script type="text/plain">alert('hello world');</script>
<script type="text/javascript">
$(document).ready(function(){
$("script[type*=plain]").each(function() {
$(this).attr('type','text/javascript');
});
});
</script>
thnx

No comments:

Post a Comment