using popupmenu, and passing the target frame's ID when clicked.Can I do this?

Discussion in 'Javascript' started by J, Jan 30, 2005.

  1. J

    J Guest

    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.tagName == "A")
    popupBodyObj.all.onclick = doClick;
    }
    popupObj.show(0, linkObj.offsetHeight+2, menuID.offsetWidth,
    menuID.offsetHeight, linkObj);

    }


    function doClick()
    {
    parent.frames(2).location = this.href;
    return false;
    }
    J, Jan 30, 2005
    #1
    1. Advertising

  2. Re: using popupmenu, and passing the target frame's ID when clicked. Can I do this?

    J wrote:
    <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.
    Richard Cornford, Jan 31, 2005
    #2
    1. Advertising

  3. J

    Randy Webb Guest

    Richard Cornford wrote:

    > J wrote:
    > <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.


    But "this.href" in that function doesn't refer to the links href
    property, it is attempting to refer to the functions href property.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Randy Webb, Jan 31, 2005
    #3
  4. Re: using popupmenu, and passing the target frame's ID when clicked. Can I do this?

    Randy Webb wrote:
    <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.
    Richard Cornford, Jan 31, 2005
    #4
  5. J

    Randy Webb Guest

    Richard Cornford wrote:
    > Randy Webb wrote:
    > <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? ;)


    You have a point ;)

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Randy Webb, Jan 31, 2005
    #5
  6. J

    Fred Oz Guest

    J wrote:
    [...]
    > popupBodyObj.innerHTML = menuID.outerHTML;
    > for (var i = 0; i < popupBodyObj.all.length; i++)
    > {
    > if (popupBodyObj.all.tagName == "A")
    > popupBodyObj.all.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.

    --
    Fred
    Fred Oz, Jan 31, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shoa
    Replies:
    1
    Views:
    25,852
    Roland
    Oct 16, 2005
  2. cpprogrammer
    Replies:
    0
    Views:
    352
    cpprogrammer
    May 8, 2006
  3. ABC
    Replies:
    0
    Views:
    581
  4. Replies:
    3
    Views:
    442
  5. Replies:
    2
    Views:
    179
Loading...

Share This Page