Loading Jquery using window.document.write()

Loading Jquery using window.document.write()

Hi everyone
 
I have this button on a page that uses " window.open" and then " document.write" to open a new browser window and then write HTML to the newly opened window. The issue is that the written HTML has <script src> tag that loads Jquery. Around the bottom of the document is the <script> $(function(){....})</script> code. But the page gives an error at the call saying that "$" is undefined. Obviously, the JQuery library was not loaded.
 
Any help?
 
Abhay