Today''s Page Hits: 155
Very tricky, use data binder can even link size of a window with other components.
try following example in zkdemo , click overlapped, resize the window.
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<zk>
<button label="overlapped" onClick="winActif.doOverlapped()" />
<label id="info" />
<window visible="false" title="Les actifs" id="winActif"
border="normal" closable="true" left="300px" top="100px" width="200px"
height="200px"
onClose="self.setVisible(false); event.stopPropagation();"
onSize='info.setValue(winActif.getWidth()+","+winActif.getHeight());'
sizable="true">
</window>
<hbox style="background-color:red"
width="@{winActif.width,load-when=winActif.onSize}"
height="@{winActif.height,load-when=winActif.onSize}">
Connected Box
</hbox>
</zk>
I posted the same question on ZK Help.
Is there any tricky in javascript to listen firefox/IE tab close?
How to do such tricky using zk?
Thanks in advance
Posted by Marcos de Sousa on May 10, 2009 at 01:06 AM CST #
check au.js
zk.addInit(function () {
//skipped..
zkau._oldBfUnload = window.onbeforeunload;
window.onbeforeunload = zkau._onBfUnload;
});
zk directly replace window.onbeforeunload. :(,
I think there should be some reason why not use zk.listen, i don't know...
zk.listen(window, "beforeunload", zkau._onBfUnload);
Posted by atticcat on May 14, 2009 at 10:35 AM CST #
a comment said '//unable to use zk.listen', don't know reaseon...
zkau._oldUnload = window.onunload;
window.onunload = zkau._onUnload; //unable to use zk.listen
Posted by atticat on May 14, 2009 at 10:36 AM CST #
I tried the code bellow with no success, Is there missing any thing?
Thanks
<zk>
<script type="text/javascript" >
zk.addInit(function () {
//zkau._oldUnload = window.onunload;
//window.onunload = zkau._onUnload;
zkau._oldBfUnload = window.onbeforeunload;
window.onbeforeunload = zkau._onBfUnload;
zk.listen(window, "showMsg", zkau._onBfUnload);
}
);
function showMsg() {
alert("Tab is Being Closed...");
}
</script>
<window width="200px" height="100%" border="normal" title="Testing Javascript" closable="true">
<grid>
<rows>
<row align="center">
<button label="Test Javascript" action="onclick: showAlerta()"/>
</row>
</rows>
</grid>
</window>
</zk>
Posted by Marcos de Sousa on May 16, 2009 at 06:11 PM CST #
I tried also,
<script type="text/javascript" >
zk.listen(window, "showMsg", zkau._onBfUnload);
function showMsg() {
alert("Tab is Being Closed...");
}
</script>
I am still trying to understand au.js
Posted by Marcos de Sousa on May 16, 2009 at 06:53 PM CST #
I found the definition of zk.listen
Now it is working.
The only problem, I know still remain here, it is related to refresh. But, I can live with it.
<script type="text/javascript" >
zk.listen(window, "beforeunload", showMsg);
function showMsg() {
alert("Tab is Being Closed...");
}
</script>
Posted by Marcos de Sousa on May 16, 2009 at 06:59 PM CST #
Thanks Atticat,
I know need only to call server function from javascript
<zk>
<!-- JAVASCRIPT -->
<script type="text/javascript" >
zk.listen(window, "beforeunload", showMsg);
function showMsg() {
if (confirm("Está a tentar fechar a aplicação ou então efectuou um refresh.\nDeseja sair da aplicação?")) {
alert("YES");
// Call an server function
}
}
</script>
<window width="150px" height="80px" border="normal" title="Testing Javascript" closable="true">
<button label="Test Javascript" action="onclick: showMsg()"/>
</window>
</zk>
Posted by Marcos de Sousa on May 16, 2009 at 07:08 PM CST #