简体   繁体   English

在窗口卸载时从javascript调用a4j:commandButton

[英]call a4j:commandButton from javascript on window unload

I am not able to call a4j:commandButton click on window unload. 我无法调用a4j:commandButton单击窗口卸载。 my jsf code is here 我的jsf代码在这里

1st the javascript in which i have window unload method and i have called button click in that function. 第一的javascript ,我有窗口卸载方法,我在该函数中调用按钮单击。

<script type="text/javascript">
    window.onbeforeunload = function() {
        document.getElementById('pForm:closeTime').click();
    }
</script>

2nd i have hidden a4j:commandButton in body 第二我在体内隐藏了a4j:commandButton

<h:form id="pForm">
<a4j:commandButton id="closeTime" value="" action="#{controller.update}" oncomplete="javascript:window.close()" style="visibility:hidden;display:none" </a4j:commandButton>
</h:form>

when window is closed this controller is not getting called. 当窗口关闭时,不会调用该控制器。 Help me out in this !!! 在这帮助我!

It's much cleaner to use jsFunction for this: 为此,使用jsFunction更加干净:

<script type="text/javascript">
    window.onbeforeunload = function() {
        closeTime();
    }
</script>

<h:form id="pForm">
    <a4j:jsFunction name="closeTime"
                    action="#{controller.update}"
                    oncomplete="window.close()"/>
</h:form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM