window.open 不会打开窗口

window.open doesn't Open a Window

本文关键字:开窗口 open window      更新时间:2023-09-26

以下标记由我的 ASP.NET MVC页面生成。

<button onclick="window.open='/Client/ReleaseForm';" type="button" class="btn btn-primary">
    View/Print Release Form
</button>

但是,单击该按钮不起作用。没有打开任何窗口,没有打开新标签页,也没有在我的 Chrome 浏览器控制台中显示任何错误。

我知道有弹出窗口阻止程序,但我的印象是,只要它是响应用户操作(例如单击按钮),它就可以工作。

谁能告诉我如何在新窗口中显示内容?

我很确定window.open是一个函数,所以你想要:

window.open('/Client/ReleaseForm');

此外,最好在 JavaScript 代码中设置事件处理程序,而不是内联。

<button id="print" type="button" class="btn btn-primary">
    View/Print Release Form
</button>
<!-- Elsewhere, in a JS file -->
document.getElementById('print')
    .addEventListener('click', function viewOrPrintReleaseForm() {
        window.open('/Client/ReleaseForm');
    });