新标签页中的HTML按钮打开链接 [英] HTML button opening link in new tab

查看:121
本文介绍了新标签页中的HTML按钮打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是按钮打开特定链接的简单代码

So this is the simple code for the button to open a certain link

                <button class="btn btn-success" onclick="location.href='http://google.com';"> Google</button>

但是它在同一页面上将其打开,但是我希望该链接在新选项卡上打开.

but it opens it on the same page, I want the link to open on a new tab though.

推荐答案

您可以使用以下内容.

window.open(
  'https://google.com',
  '_blank' // <- This is what makes it open in a new window.
);

HTML格式

 <button class="btn btn-success" onclick=" window.open('http://google.com','_blank')"> Google</button>

plunkr

这篇关于新标签页中的HTML按钮打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆