Hi,
I'm using the following code snippet to show popup menus (in a header
frame) and target the menu options to another frame. This works fine for
a single hard-coded frame (e.g. "2" below, in doClick) but I need to
pass in the target frame ID when the user clicks, the reason being that
different options will target different frames depending on who the user is.
the target frame name is in the target attribute of the link tag, i.e.
<a href="" target="here"> that the user clicks on but I don't know how
to make use of this in the code below.
Hope that makes sense, can anyone help?
J
function showMenu(linkObj, menuID)
{
var popupObj = window.createPopup();
var popupBodyObj = popupObj.document.body;
popupBodyObj.style.border = "0px black solid";
popupBodyObj.style.color="99ccff";
popupBodyObj.style.hover="red";
popupBodyObj.innerHTML = menuID.outerHTML;
for (var i = 0; i < popupBodyObj.all.length; i++)
{
if (popupBodyObj.all[i].tagName == "A")
popupBodyObj.all[i].onclick = doClick;
}
popupObj.show(0, linkObj.offsetHeight+2, menuID.offsetWidth,
menuID.offsetHeight, linkObj);
}
function doClick()
{
parent.frames(2).location = this.href;
return false;
}
Richard Cornford - 31 Jan 2005 01:47 GMT
<snip>
> function doClick()
> {
> parent.frames(2).location = this.href;
> return false;
> }
In any context where - this.href - can be used to reference the HREF of
a link - this.target - can be used to reference its TARGET attribute's
value.
(Incidentally, code posted to newsgroups should be formally block
indented, preferably with 2-4 space characters, if you want people to
read the code. The FAQ covers the details.)
Richard.
Randy Webb - 31 Jan 2005 02:00 GMT
> <snip>
>
[quoted text clipped - 7 lines]
> a link - this.target - can be used to reference its TARGET attribute's
> value.
But "this.href" in that function doesn't refer to the links href
property, it is attempting to refer to the functions href property.

Signature
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Richard Cornford - 31 Jan 2005 02:19 GMT
<snip>
> But "this.href" in that function doesn't refer to the
> links href property, it is attempting to refer to the
> functions href property.
You don't expect me to actually read code that has not been presented in
a properly indented form to the extent of understanding what - this -
may refer to in any context, do you? ;)
Richard.
Randy Webb - 31 Jan 2005 03:15 GMT
> <snip>
>
[quoted text clipped - 5 lines]
> a properly indented form to the extent of understanding what - this -
> may refer to in any context, do you? ;)
You have a point ;)

Signature
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Fred Oz - 31 Jan 2005 03:23 GMT
[...]
> popupBodyObj.innerHTML = menuID.outerHTML;
> for (var i = 0; i < popupBodyObj.all.length; i++)
> {
> if (popupBodyObj.all[i].tagName == "A")
> popupBodyObj.all[i].onclick = doClick;
> }
This snippet (and likely others) makes your code IE only. Is
that your intention? If not, other methods can be used that
allow non-IE browsers to use your page.

Signature
Fred