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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick

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

    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_rin g_r1_c1">
    <area shape="circle" coords="30,30,3 0"
    href="javascrip t:show_details( 'ring1');" alt="ring1" title="ring1">
    </map>

    Is it possible to modify the

    href="javascrip t:show_details( 'ring1');"

    to something like

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

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

  • Lasse Reichstein Nielsen

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

    Nick <nbdy9.nospam@h otmail.com> writes:
    [color=blue]
    > 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_rin g_r1_c1">
    > <area shape="circle" coords="30,30,3 0"
    > href="javascrip t:show_details( 'ring1');" alt="ring1" title="ring1">
    > </map>
    >
    > Is it possible to modify the
    >
    > href="javascrip t:show_details( 'ring1');"
    >
    > to something like
    >
    > href="javascrip t:show_details( embeddedObject. tags.alt);"[/color]

    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.
    [color=blue]
    > So the 'alt' of area shape will be the parameter of teh show_details
    > function?[/color]

    <area shape="circle" coords="30,30,3 0"
    href="thisLinkN eedsJS.html" alt="Foobar" title="Informat ion about Foobar"
    onclick="show_d etails(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 - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Nick

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

      Lasse Reichstein Nielsen wrote:[color=blue]
      > Nick <nbdy9.nospam@h otmail.com> writes:
      >
      >[color=green]
      >>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_rin g_r1_c1">
      >> <area shape="circle" coords="30,30,3 0"
      >> href="javascrip t:show_details( 'ring1');" alt="ring1" title="ring1">
      >></map>
      >>
      >>Is it possible to modify the
      >>
      >>href="javascr ipt:show_detail s('ring1');"
      >>
      >>to something like
      >>
      >>href="javascr ipt:show_detail s(embeddedObjec t.tags.alt);"[/color]
      >
      >
      > 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.
      >
      >[color=green]
      >>So the 'alt' of area shape will be the parameter of teh show_details
      >>function?[/color]
      >
      >
      > <area shape="circle" coords="30,30,3 0"
      > href="thisLinkN eedsJS.html" alt="Foobar" title="Informat ion about Foobar"
      > onclick="show_d etails(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[/color]

      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="javascrip t:;" to void the page scrolling to beginning.

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

      Comment

      • Lasse Reichstein Nielsen

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

        Nick <nbdy9.nospam@h otmail.com> writes:
        [color=blue]
        > I am using javascript to open a popup window.[/color]

        Dangerous.
        [color=blue]
        > It can also be done using onclick. However, I don't want the main
        > page go to any url.[/color]

        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.
        [color=blue]
        > And the dreamweaver use href="#"[/color]

        Bad idea. Even href="" is better, but neither are the slightest bit
        useful to someone with no Javascript.
        [color=blue]
        > 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).[/color]

        unless you return false, i.e.,
        onclick="show_d etails(this.alt );return false;"
        [color=blue]
        > Currently I am using
        >
        > href="javascrip t:;" to void the page scrolling to beginning.[/color]

        Worse, for all the reasons in the FAQ.
        [color=blue]
        > And I also found that href="javascrip t:showPopup(thi s.alt)" doesn't
        > work. but onclick="javasc ript:showPopup( this.alt)" works
        > well. Interesting.... (I tested it on IE 6).[/color]

        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 - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Nick

          #5
          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.Ne t'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.

          Comment

          Working...