Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call javascript function in ZK

Tags:

javascript

zk

In ZK framework, inside zul file i want to call javascript function but it does not happens.

<a label="Click" onClick="popUp();">

I have that popUp() function also. But when I click on

<script type="text/javascript">
    function createPopUp(url)
    {
        var w = 600;
        var h = 500;
        var left = (screen.width/2)-(w/2);
        var top = (screen.height/2)-(h/2);
        window.open(url,'name','scrollbars=yes,width='+w+', height='+h+', top='+top+', left='+left);
    }
</script>

But when I click on that link it dispalys following error:

Sourced file: inline evaluation of: `` popUp();'' : 
Command not found: popUp() : at Line: 13 : 
in file: inline evaluation of: `` popUp();'' : popUp ( ) 
like image 262
Narayan Subedi Avatar asked Dec 13 '12 06:12

Narayan Subedi


2 Answers

To solve this problem I found below way:

<a label="Click" xmlns:w="http://www.zkoss.org/2005/zk/client" w:onClick="createPopUp('http://www.facebook.com/prabhatsubedi');"/>
like image 123
Narayan Subedi Avatar answered Sep 19 '22 10:09

Narayan Subedi


As an alternative, if you want to achieve this in java, rather than .zul file, you can use

label.setWidgetListener(Events.ON_CLICK, "popUp();");

as indicated here with javadoc

like image 43
asyard Avatar answered Sep 21 '22 10:09

asyard