简体   繁体   English

使用 document.write 在新窗口中打开 JavaScript 链接

[英]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>

Please stop using String.link .请停止使用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:您可以使用适当的target属性( 阅读更多)构建一个链接以在新选项卡中打开,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM