The first part of your question (opening a new tab) is a duplicate of this question:
StackOverflow
I'm not entirely sure what you mean by "write," but I answered what I think you're asking.
As for writing into a new window/tab with JS, you can do that 2 ways:
- Open a url on your website in a new window/tab
- Make a new window and use
document.write()
Tutorial: W3 Schools
Now that I know what you want to do specifically, you can do this:
window.open("https://mail.google.com/mail/u/0/#inbox?compose=new");
to open gmail in a new window/tab. You cannot write into any elements in that window (the subject line, for example) with JS because the same-origin policy does not allow it (you do not own google.com). Thus, you cannot accomplish what you want to do unless you are writing into a new window on your own website or file directory.
This StackOverflow post tells you how to set up a mailto
that can auto set the subject and body. It's not exactly what you want, but maybe you could adapt it.