Make JavaScript link open in new window with document.write

I’m to figure out how to code so that the link opens into a new window? Is this the correct way to do that?

<script>
  var copyright = "&copy; ";
  var d = new Date();
  var n = d.getFullYear();
  var db = " Doing Business";
  var str = new String(" Link");
  document.write(copyright + n + str.link("https://www.google.com"));
  document.write(db); 
</script>

Answer

Please stop using String.link. It’s old, deprecated, and smelly. It also doesn’t support what you are trying to do.

You can construct a link with the appropriate target attribute (read more) to open in a new tab as follows:

var myLink = "<a target='_blank' href='https://www.google.com'>Link</a>";
document.write(copyright + n + " " + myLink);