I want to open a new window during runtime using javascript.

I want to wait till that new window has finished loading everything and thus has readystate="complete". After this i then want to use a function (maybe xmlhttprequest) to get the full source code of that new window.

How would i do this?