Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:12

Hyperlink


Poster: darkcircuituk
Dated: Tuesday August 31 2004 - 12:09:54 BST

Moderator Addition: This thread is very much related to this one. If you're interested in dynamic context menus, you might want to read both threads. --Kevin
<hr>
Using the right click menu, is it possible to tell if you are right clicking on a hyperlink? Because I wish to change the menu that is displayed, when someone right clicks on a hyperlink!

Dave


Poster: Andy
Dated: Wednesday September 1 2004 - 16:48:37 BST

Hi,

The new version of contextmenu.js includes a new property called contextObject

This property is set for ALL HTML objects and returns the following:

contextObject.tagName
contextObject.id
contextObject.parentElement
contextObject.innerHTML
contextObject.className

The object will also contain certain references based on what the object is. For example, if it were an image it would include contextObject.src or a link will contain contextObject.href and so on.

Hope this helps
Andy

Halfway there


Poster: darkcircuituk
Dated: Thursday September 9 2004 - 10:28:30 BST

Okay I am halfway there, thanks to the help of team member kevin I have managed to get one menu to load when someone right clicks on a hyperlink and another menu to load when someone right clicks on any other part of the page.

I tried implementing your solution, I downloaded the latest contextmenu.js file (1.2), this included the next contextobject option which was great but the major problem I have is returning the contextObject value to the menu_data.js file. I tried using the solution offered by team member kevin and this didn't work:

Code:
function mm_setUrlToOpen()
{
  _mi[_itemRef][2] = contextObject.href;
  itemOff(_itemRef);
  itemOn(_itemRef);
 
}


What I wish to do is allow the menu_data.js file to find out the address that the hyperlink points to and then open the page at that address. I can open the page easily enuff, but what I need is a way in which to get the address of the hyperlink that has been right clicked on.

How do I go about programming this? At the moment the menu_data.js file does not recognise the contextObject variable within the contextmenu.js file because the variable is not being passed to the menu_data.js file.

Thanks for any help you can offer,

Dave

It's okay I worked it out


Poster: darkcircuituk
Dated: Thursday September 9 2004 - 13:45:25 BST

Rather than placing the new code for the contextmenu.js file (which seems to be redundant), I placed it in the menu_data.js file and now it works perfectly, thank you very much for your help. Rather than using contextObject.href, which just returned nothing, I used contextObject.parentElement and that returned exactly what I needed.

Thank you again

Dave

Spoke too soon


Poster: darkcircuituk
Dated: Thursday September 9 2004 - 16:20:08 BST

Okay I have the weirdest thing happening right now and I can think of no way to explain it :-S

As part of our page we are using a text hyperlink as well as using the small icon image next to it as a hyperlink. This seems to cause problems as image hyperlinks like you to use contextObject.parentElement (if you use contextObject.href it just returns the address of the image itself) and text hyperlinks like you to use contextObject.href (if you use contextObject.parentElement you get an result that says [object]).

I was confused by this because on one of my earlier pages the contextObject.parentElement command worked fine for both images and text hyperlinks :?: So I investigated why it worked in this one instance and I came out with a really confusing answer. The earlier text hyperlinks were enclosed in header tags:

Code:
<a href="business_modeling/pa_bm_overview.htm"><h4 valign="middle">Business Modelling</h4></a>


So I decided to try using header tags around the non-working text hyperlinks and guess what? it worked, but the problem is, I don't wanna use header tags around the text hyperlinks I just want normal code:

Code:
<a href="requirements/pa_req_overview.htm">Requirements</a>

Can you give me a solution to this problem without me having to change the contextObject.parentElement command and without me having to change the format of my text hyperlinks?

Thanks for any help you can offer

Dave

Fixed it


Poster: darkcircuituk
Dated: Thursday September 9 2004 - 16:22:22 BST

I replaced the header tag with div and it works fine, not sure why, but it works :-D

Re: Halfway there


Poster: kevin3442
Dated: Thursday September 9 2004 - 21:29:08 BST

Hi Dave,
darkcircuituk wrote:
I tried implementing your solution, ... but the major problem I have is returning the contextObject value to the menu_data.js file. I tried using the solution offered by team member kevin and this didn't work:

Code:
function mm_setUrlToOpen()
{
  _mi[_itemRef][2] = contextObject.href;
  itemOff(_itemRef);
  itemOn(_itemRef);
 
}


Just in case other people end up trying this, I want to point out that it does in fact work. Here is a working example. I'm not sure what you mean by "...returning the contextObject value to the menu_data.js file..." the contextObject is a global object, so the file where it is defined doesn't matter so much. In the mm_setUrlToOpen() function above, contextObject.href is the value of the href attribute of the link that was right clicked to open the context menu. That href value is assigned to the url property of the menu item when you mouse over the item. Through this dynamic assignment of a menu item's url property, when the menu item is eventually clicked, it will go to the correct url.

darkcircuituk wrote:
What I wish to do is allow the menu_data.js file to find out the address that the hyperlink points to and then open the page at that address.

I think part of the confusion is that you may be focusing on what things are in what files. You don't really assign a value to a file. You assign a value to another variable, or send it to another function, etc.

darkcircuituk wrote:
I can open the page easily enuff, but what I need is a way in which to get the address of the hyperlink that has been right clicked on.

That's exactly with the mm_setUrlToOpen() funciton does... it takes the address of the hyperlink that was right clicked on and puts it into the url property of the "Open" and "Open in a New Window" menu items when they are moused over. That way, if you eventually click on of those two menu items, their url is properly set and they will open the appropriate page. So... mousing over an item sets its url, then clickng on the item activates it.

Quote:
How do I go about programming this? At the moment the menu_data.js file does not recognise the contextObject variable within the contextmenu.js file because the variable is not being passed to the menu_data.js file.

Again, I think you're focusing too much on what code is in what file. Javascript functions, variables, objects, etc. are not really restricted to the .js file where they are defined. Once that .js file is loaded into a page, it's code becomes available to any other entity in the same page. The contextObject is a global object, so its internal values (its "members") are available to any function or variable within the page, regardless of which .js file contains the function or variable definition.

I'm not sure what's going on with the image vs. text link thing. You have me curious so I'll prbably go mess around with it some. If I find anything out I'll let you know. In the mean time, the most important thing is that it works the way you want it to. ;)

Cheers,

Kevin


Poster: darkcircuituk
Dated: Friday September 10 2004 - 7:28:12 BST

The problem I had was that I was not actually implementing the contextmenu.js file, it was actually redundate in my menu. Instead all the code from that file was present in my menu_data.js file and that is why I got confused about why I couldn't get menu_data.js to recognise the contextObject variable.