首页 > 解决方案 > 如何使按钮 onclick 动作在新窗口中打开?

问题描述

我试图创建一个链接到在新窗口中打开的 PDF 文件的按钮。尝试了 _blank 方法,但没有奏效。

<button onClick="parent.location='files/sample.pdf'" class="send" >Curriculum vitae</button>
</form>

代码

标签: html

解决方案


您可以使用锚标记并为其设置样式

<a class="btn btn-success" href="https://www.google.com" target="_blank">Google</a>

或者您可以将按钮更改为

<button title="button title" class="action primary tocart" onclick=" window.open('http://www.google.com', '_blank'); return false;">Google</button>

推荐阅读