【问题标题】:My page is opening a new tab and I don't know why我的页面正在打开一个新标签,我不知道为什么
【发布时间】:2021-12-11 15:55:42
【问题描述】:

我有一个网页,当输入日期正确时必须下载 XLS,但如果输入日期不正确,它必须显示一条消息并停止下载过程。

一切正常,当日期不正确时,我会建议用户,但每次单击按钮时都会打开一个新选项卡。如果日期正确,它会打开一个新选项卡,但在下载 XLS 时它会关闭,如果不正确,它会建议用户,但它会打开新选项卡并且不会关闭它。如何修复它而不打开新标签?

我把我的代码放在下面:

HTML:

        <div class="botonera">
            <a4j:commandLink id="regimenConcertadoLink"
                styleClass="botonAplicacionTXT"
                action="#{descargaInformesBean.validarInformeRegimenConcertado()}"
                oncomplete="if(#{descargaInformesBean.informeRegimenConcertadoValido}){#{rich:element('descargaInforme')}.onclick();}"
                status="waitStatus">
                <h:outputText value="Descargar Informe" />
                <h:graphicImage value="/img/ico_descargar.gif"
                    alt="Descargar Informe"
                    title="Descargar Informe" />
                <f:param name="requiredValidator"
                    value="requiredValidator" />
            </a4j:commandLink>
            <h:commandLink id="descargaInforme"
                styleClass="botonAplicacionTXT" target="_blank"
                action="#{descargaInformesBean.descargarInformeIngresos()}">
            </h:commandLink>
        </div>

JAVA:

 public void descargarInformeIngresos() throws ServiceException, IOException {        
    if ((filtroFechaDesde != null && filtroFechaHasta != null) || (filtroFechaIngresoDesde != null && filtroFechaIngresoHasta != null)) {
        //DOXMLSTUFF 
    }else {
        AtlasFacesUtils.addErrorMessageFromBundle("error.fecha.vacia");
    }
}

正如您在代码中看到的,如果两个日期都为空,我什么都不做,并显示一条消息来建议用户,这工作正常,但仍然打开一个新标签,我不想这样做

谢谢!

【问题讨论】:

    标签: java html web download tabs


    【解决方案1】:

    我认为这是由于您使用的目标标记属性造成的。

    target="_blank" 打开一个新标签

    尝试将其更改为

    target="_self" 看看能不能解决。

    【讨论】:

    • 成功了,非常感谢!!!
    • 太棒了!!!我建议阅读这篇文章以更好地了解该标签中发生的事情。 w3schools.com/tags/att_a_target.asp
    • 祝你玩得开心,伙计
    猜你喜欢
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 1970-01-01
    • 2020-05-07
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    相关资源
    最近更新 更多