Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Russ on Jul 24, 2009 01:35
open dhtmlx forum
problems with onClick url event handler for xml

Hi there,

First of all, thanks for this menu system, been looking for a decent xml based javascript menu for a long time!

I'm having some issues with the menu though. It renders out fine on the page but the onclick url event won't work! Please help :-)

Here is my html code:

----------------------------------------------------

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DHTMLX Menu Test</title>
<link rel="stylesheet" type="text/css" href="dhtmlx/skins/dhtmlxmenu_standard.css">
<script src="dhtmlx/dhtmlxcommon.js"></script>
<script src="dhtmlx/dhtmlxmenu.js"></script>
</head>

<body onload="initMenu();">

<div class="menu">
<div id="menuObj"></div>
<script>
var menu;
    function initMenu() {
        menu = new dhtmlXMenuObject("menuObj","standard");
        menu.setImagePath("dhtmlx/imgs/");
        menu.setIconsPath("dhtmlx/imgs/");
        menu.attachEvent("onClick",function(id){var url = menu.getUserData(id,"url")});
        menu.loadXML("dhtmlx/xml_template.xml");
    }

</script>
</div>

</body>
</html>

----------------------------------------------------

Here is my xml:

----------------------------------------------------

<menu>
<item id="Home" text="Home><userdata name="url">index.html</userdata></item>
</menu>

----------------------------------------------------

What am I doing wrong?

Thanks,

Russell
Answer posted by Alex (support) on Jul 24, 2009 02:15

Hello, 

the issue wasn't reproduced locally - the sample is attached. 

But onclick isn't called for complex items (when item has children). In order to enable onclick in this case you can modify the following line in the dhtmlxmenu.js, _doOnClick method:

  if (type.charAt(0)=="c") { return; } // can't click on complex item
try to replace it with:
  if (type.charAt(0)=="c") {this.callEvent("onClick", [id]); return; } // can't click on complex item



Attachments (1)
Answer posted by Russ on Jul 24, 2009 04:12
Thanks for this, I tried putting this in the js though and to no effect :-/

I am trying to make it so that the menu system can be used to navigate a website. Is this possible?

The menu loads up fine, but it still doesn't go to the url link from my xml file when clicked. If I put the alert function from your sample in, it does pick up the url though and puts it in a popup alert window. I'm at a loss!

Thanks in advance.
Answer posted by Alex (support) on Jul 24, 2009 05:17

What approach do you use open new window ? 

The possible way is:

 menu.attachEvent("onClick",function(id){

var url = menu.getUserData(id,"url")

window.open(url);

});

Answer posted by Russ on Jul 24, 2009 05:24
Thanks!

This has almost worked now.

It opened the link in a new window/tab. How do I make it open in the same one? ie: the parent window

Cheers,

Russell
Answer posted by Russ on Jul 24, 2009 05:38
I think I've got it now, thanks for your help!

window.location.href=(url);

Thanks again :-)