Open a new tab with custom HTML instead of a URL

kasper Taeymans picture kasper Taeymans · May 13, 2012 · Viewed 41.7k times · Source

I'm making a Greasemonkey script and would like to open a new tab which will not display a URL but some HTML that is part of the script. So basically I want to do something like this (which is obviously not working):

window.open('<html><head></head><body></body></html>');
or
GM_openInTab('<html><head></head><body></body></html>');

Any hints are welcome!

Answer

aL3891 picture aL3891 · May 13, 2012

You can do this:

var newWindow = window.open();

and then do

newWindow.document.write("ohai");