How to open a blank tab and insert JS?

For some reason when i go to inject code i cant put a closing tag </script> or it just inserts my JS code from their on out into my current html.

This was the code i used:

var src= "jquery-3.2.1.min.js"
var x = window.open("").document.write('<script src = '+src+' type="text/javascript" >$(document).ready(function(){window.close()});')

Doesn’t work? If i check the inspect of the blank tab it is present.