以下标记是由我的 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');
});
关于javascript - window.open 不打开窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28264993/