I don't understand why you are doing this, but it is possible... :)
If you must insert javascript code at the begining of the tag body, you can load your javascript file like a "jsonp ajax call" and inside it call to 'prepend' jquery function.
Example:
<html>
<head>
<title>test</title>
</head>
<body>
<h1>Test</h1>
<p>Test</p>
<script type="text/javascript" src="https://code.jquery.com/ui/1.9.2/jquery-ui.min.js"></script>
<script type="text/javascript">
$( document ).ready( function() {
$.ajax({
dataType: "jsonp",
url: "myscript.js"
})
.done( function( d, response ) {
console.log( "JS LOADED" );
});
});
</script>
</body>
</html>
And in your "myscript.js" file something like:
$( "body" ).prepend( "<script>" +
"var a = 1;" +
"console.log( a );" +
"/* AND ALL THE JS CODE TO INSERT " +
"AT THE BEGINING OF TAG BODY */</script>" );
Don't forget with the semicolon (;) at the end of every js line.
$.getScript('myscript.js');? Docs: api.jquery.com/jQuery.getScript<script src="myscript.js"></script>in the HTML) to see if it works? Also, where are you running your script?scripttag to the page with JavaScript, then the entire reason of placing thescripttag before thebodytag has already been defeated.