Any variable in embedded javascript to reference the object embedsthe script?

Discussion in 'Javascript' started by Nick, Feb 28, 2004.

  1. Nick

    Nick Guest

    For example, I have the following code:

    <img src="photo_ring_r1_c1.jpg" title="" alt="Rings"
    style="width: 200px; height: 150px;" usemap="#photo_ring_r1_c1">
    <map name="photo_ring_r1_c1">
    <area shape="circle" coords="30,30,30"
    href="javascript:show_details('ring1');" alt="ring1" title="ring1">
    </map>

    Is it possible to modify the

    href="javascript:show_details('ring1');"

    to something like

    href="javascript:show_details(embeddedObject.tags.alt);"

    So the 'alt' of area shape will be the parameter of teh show_details
    function?
    Nick, Feb 28, 2004
    #1
    1. Advertising

  2. Re: Any variable in embedded javascript to reference the objectembeds the script?

    Nick <> writes:

    > For example, I have the following code:
    >
    > <img src="photo_ring_r1_c1.jpg" title="" alt="Rings"
    > style="width: 200px; height: 150px;" usemap="#photo_ring_r1_c1">
    > <map name="photo_ring_r1_c1">
    > <area shape="circle" coords="30,30,30"
    > href="javascript:show_details('ring1');" alt="ring1" title="ring1">
    > </map>
    >
    > Is it possible to modify the
    >
    > href="javascript:show_details('ring1');"
    >
    > to something like
    >
    > href="javascript:show_details(embeddedObject.tags.alt);"


    Yes. First of all, you should not use a "javascript:"-URL. For several
    reasons <URL:http://jibbering.com/faq/index.html#FAQ4_24>.
    Instead, use the onclick attribute.

    You should also use the title attribute appropriately. It should contain
    information that further describes the element. The alt attribute
    should be used for information that is shown when the browser can't
    show the area graphically (e.g., a text browser). They are not the same,
    and should be used differently.

    > So the 'alt' of area shape will be the parameter of teh show_details
    > function?


    <area shape="circle" coords="30,30,30"
    href="thisLinkNeedsJS.html" alt="Foobar" title="Information about Foobar"
    onclick="show_details(this.alt);">

    The href should point to a page that explains that your page requires
    Javascript to function correctly (and why, if you can defend it).
    A signifiacnt number of people browse with Javascript turned off
    or not available.

    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Feb 28, 2004
    #2
    1. Advertising

  3. Nick

    Nick Guest

    Re: Any variable in embedded javascript to reference the objectembeds the script?

    Lasse Reichstein Nielsen wrote:
    > Nick <> writes:
    >
    >
    >>For example, I have the following code:
    >>
    >><img src="photo_ring_r1_c1.jpg" title="" alt="Rings"
    >> style="width: 200px; height: 150px;" usemap="#photo_ring_r1_c1">
    >><map name="photo_ring_r1_c1">
    >> <area shape="circle" coords="30,30,30"
    >> href="javascript:show_details('ring1');" alt="ring1" title="ring1">
    >></map>
    >>
    >>Is it possible to modify the
    >>
    >>href="javascript:show_details('ring1');"
    >>
    >>to something like
    >>
    >>href="javascript:show_details(embeddedObject.tags.alt);"

    >
    >
    > Yes. First of all, you should not use a "javascript:"-URL. For several
    > reasons <URL:http://jibbering.com/faq/index.html#FAQ4_24>.
    > Instead, use the onclick attribute.
    >
    > You should also use the title attribute appropriately. It should contain
    > information that further describes the element. The alt attribute
    > should be used for information that is shown when the browser can't
    > show the area graphically (e.g., a text browser). They are not the same,
    > and should be used differently.
    >
    >
    >>So the 'alt' of area shape will be the parameter of teh show_details
    >>function?

    >
    >
    > <area shape="circle" coords="30,30,30"
    > href="thisLinkNeedsJS.html" alt="Foobar" title="Information about Foobar"
    > onclick="show_details(this.alt);">
    >
    > The href should point to a page that explains that your page requires
    > Javascript to function correctly (and why, if you can defend it).
    > A signifiacnt number of people browse with Javascript turned off
    > or not available.
    >
    > /L


    I am using javascript to open a popup window. It can also be done using
    onclick. However, I don't want the main page go to any url. And the
    dreamweaver use href="#" and it really annoy because the page always
    scroll to the beginning of the hmtl after click the map (and it will
    always go to the URL of href if putting any URL there).

    Currently I am using

    href="javascript:;" to void the page scrolling to beginning.

    And I also found that href="javascript:showPopup(this.alt)" doesn't
    work. but onclick="javascript:showPopup(this.alt)" works well.
    Interesting.... (I tested it on IE 6).
    Nick, Feb 28, 2004
    #3
  4. Re: Any variable in embedded javascript to reference the objectembeds the script?

    Nick <> writes:

    > I am using javascript to open a popup window.


    Dangerous.

    > It can also be done using onclick. However, I don't want the main
    > page go to any url.


    In that case, do as the FAQ says, not as I say :)
    Because I forgot to add the "return false" at the end of the onclick
    handler which would prevent the normal operation of the link.

    > And the dreamweaver use href="#"


    Bad idea. Even href="" is better, but neither are the slightest bit
    useful to someone with no Javascript.

    > and it really annoy because the page always scroll to the beginning
    > of the hmtl after click the map (and it will always go to the URL of
    > href if putting any URL there).


    unless you return false, i.e.,
    onclick="show_details(this.alt);return false;"

    > Currently I am using
    >
    > href="javascript:;" to void the page scrolling to beginning.


    Worse, for all the reasons in the FAQ.

    > And I also found that href="javascript:showPopup(this.alt)" doesn't
    > work. but onclick="javascript:showPopup(this.alt)" works
    > well. Interesting.... (I tested it on IE 6).


    That is because the javascript in the first is executed in the global
    scope (just as if you typed it in the address line), so "this" refers
    to the global object. The second is executed as a property of the
    element, so "this" refers to the element.

    You don't need "javascript:" in front of onclick handlers!
    By coincidence, it is not a syntax error, but it doesn't do anything.

    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Feb 28, 2004
    #4
  5. Nick

    Nick Guest

    Re: Any variable in embedded javascript to reference the objectembeds the script?

    Thanks very much. I've changed according to your suggestions. However,
    for the browsers without javascript(or dissabled). Currently it seems
    javascript is so widely used and some tools like VisualStudio.Net's
    ASP.Net development environment even automatically generate javascript
    when dragging the component to the web page. I guess some JSP
    development tools do the same too.

    So hopefully, Javascript is automatically supported by most end-users'
    browser.
    Nick, Feb 28, 2004
    #5
    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. Colin Paul Gloster
    Replies:
    48
    Views:
    1,869
    Colin Paul Gloster
    Apr 10, 2007
  2. Replies:
    1
    Views:
    476
    Mark Rae [MVP]
    Sep 20, 2007
  3. Replies:
    1
    Views:
    471
    Gabriel Genellina
    Apr 7, 2008
  4. Thomas Dodds

    Databind an embedded control in an embedded datagrid

    Thomas Dodds, Jul 26, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    394
    Thomas Dodds
    Jul 26, 2004
  5. Davide Bruzzone
    Replies:
    2
    Views:
    239
    Davide Bruzzone
    Aug 4, 2003
Loading...

Share This Page