Javascript 在一个新的浏览器窗口中打开thymeleaf链接

Javascript 在一个新的浏览器窗口中打开thymeleaf链接,javascript,spring,spring-mvc,thymeleaf,Javascript,Spring,Spring Mvc,Thymeleaf,我知道这里有很多类似的问题,但没有一个能帮我解决问题 客户端需要的是:单击按钮,然后打开一个包含给定参数的新窗口,并显示一个包含从数据库加载的动态数据的视图 到目前为止我所做的: 我有一个带有链接的视图,而不是按钮: <a th:href="@{/report/reportPrintView(al=false, mlVersion=${report.version}, sv=true, id=${report.orderId})}" target="_blank">Protokoll

我知道这里有很多类似的问题,但没有一个能帮我解决问题

客户端需要的是:单击按钮,然后打开一个包含给定参数的新窗口,并显示一个包含从数据库加载的动态数据的视图

到目前为止我所做的: 我有一个带有链接的视图,而不是按钮:

<a th:href="@{/report/reportPrintView(al=false, mlVersion=${report.version}, sv=true, id=${report.orderId})}" target="_blank">Protokoll</a>
<a th:href="@{/report/reportPrintView(al=true, mlVersion=${report.version}, sv=false, id=${report.orderId})}" target="_blank">Airline</a>
视图显示在新的浏览器选项卡中,并按预期工作,但如前所述,客户端需要一个新窗口

为了解决客户的愿望,我尝试了以下方法:

function openWin(id, mlVersion, al, sv) {
    var url = "/report/reportPrintView.html?al=" + al + "&mlVersion=" + mlVersion + "&sv=" + sv + "&id=" + id;
    ReportPrintPreview = window.open("about:blank", "ReportPrintPreview", "width=666,height=700left=250,top=50,dependent=yes,menubar=no,status=no,resizable=yes,toolbar=no,scrollbars=yes");
    ReportPrintPreview.location.href = url;
    ReportPrintPreview.focus();
    return false;
}
.
.
.
<button th:onclick="'openWin(\'' + ${report.orderId} + '\', \'' + ${report.version} + '\', false, true)'">Protokoll</button>
<button th:onclick="'openWin(\'' + ${report.orderId} + '\', \'' + ${report.version} + '\', true, false)'">Airline</button>
这里发生的情况是,打开一个新窗口时出现404错误,带有按钮的网页显示400错误。因此,我假设控制器没有得到get请求,并且不能将视图显示为合理的结果,因为它不是像@{/report/…}那样的ThymileAF调用。
有什么方法可以让它运行吗?

对于thymeleaf,它以不同的方式工作。试试下面

th:target="_blank"

这就是我的结构

JavaScript

function openWin(url) {
    ReportPrintPreview = window.open("about:blank", "ReportPrintPreview", "width=666,height=700left=250,top=50,dependent=yes,menubar=no,status=no,resizable=yes,toolbar=no,scrollbars=yes");
    ReportPrintPreview.location.href = url;
    ReportPrintPreview.focus();
    return false;
}
百里香

<button
  th:data-url="@{/report/reportPrintView(al=false, mlVersion=${report.version}, sv=true, id=${report.orderId})}"
  onclick="openWin(this.getAttribute('data-url'))">Protokoll</button>

<button
  th:data-url="@{/report/reportPrintView(al=true, mlVersion=${report.version}, sv=false, id=${report.orderId})}"
  onclick="openWin(this.getAttribute('data-url'))">Airline</button>

谢谢你的回答。并不是说你认为我忽略了它,而是我不能在明天之前尝试。然后我会给你反馈。因为客户想要按钮而不是链接,我宁愿选择下面的Metroids答案作为接受答案。不过还是要谢谢你的帮助,谢谢你的回答。并不是说你认为我忽略了它,而是我不能在明天之前尝试。我会给你反馈的,先生,这解决了我的问题。非常感谢你。简短备注:th:onclick调用应该如下所示:th:onclick='openWinthis.getAttribute\'data-url\围绕openWin。。。使用“”并转义“数据url”@Raistlin—如果您注意到的话,我使用了onclick而不是th:onclick,因为thymeleaf不需要处理该属性。在这种情况下你不必逃避。哦,谢谢你的提示。你完全正确。
<button
  th:data-url="@{/report/reportPrintView(al=false, mlVersion=${report.version}, sv=true, id=${report.orderId})}"
  onclick="openWin(this.getAttribute('data-url'))">Protokoll</button>

<button
  th:data-url="@{/report/reportPrintView(al=true, mlVersion=${report.version}, sv=false, id=${report.orderId})}"
  onclick="openWin(this.getAttribute('data-url'))">Airline</button>