unusual behaviour

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

    unusual behaviour

    Hi

    The following functions are working propery for IE, Ns 4.x and NS 6+ but
    the image I want to display disappears in IE. Why?

    function swapPic(layer,i mgName,imgObj) {
    o = (n &&
    layer?document. layers[layer].document.image s[imgName]:document.image s[imgName]);
    if(!o.hasswappe d) o.src = eval(imgObj+".s rc");
    }

    var oRef = null;
    var oRefImg = null;
    function keepPic(layer,i mgName,imgObj) {
    if(oRef) {
    // swap image back
    oRef.src = oRefImg;
    }
    if (document.image s) {
    o = (n &&
    layer?document. layers[layer].document.image s[imgName]:document.image s[imgName]);
    if(o) {
    oRef = o
    oRefImg = o.src;
    o.src = eval(imgObj+".s rc");
    o.hasswapped = true;
    }
    }
    }

    I use the following link to chose the image I want to display

    <area shape="poly" alt="" coords="25,25,2 1,0,30,0"
    href="javascrip t:void(0)" title=""
    onMouseOver="sw apPic('metera', 'diala','img1') ;"
    onClick="keepPi c('metera','dia la','img1');">

    <div id="metera"><im g src="images/pointer.aa.gif" alt="" name="diala"
    id="diala" width="50" height="50" border="0" usemap="#dialit a"></div>

    The image map is a dial with 20 positions on it to display a position on
    a dial

    --
    Cheers!
    Ken Tuck
    EyeCreate Inc.
    Web Site Design | Online Applications | E-Commerce
    ph: 705 755-1120
    fx: 705 743-9259


  • Lasse Reichstein Nielsen

    #2
    Re: unusual behaviour

    Ken Tuck <webmaster@eyec reate.net> writes:
    [color=blue]
    > The following functions are working propery for IE, Ns 4.x and NS 6+
    > but the image I want to display disappears in IE. Why?[/color]

    That is hard to say. When asking for help, you should always supply
    these three pices of infomration:

    1) What are you doing? (posting or giving a link to *all* of the code
    that fails, preferably by cutting down to a *minimal* example that
    still exhibits the flaw. If posting code, don't let lines be more than
    72 characters wide).

    2) What is it supposed to do? All you say is that it is "working
    properly", which means we have to guess what the code is supposed to
    do (and code is *not* self explanatory, especially when it is known to
    be bugged).

    3) What does it do? What do you mean by "disappears "? Is it blank, is
    it not in the page flow at all, or what? Be exact.
    [color=blue]
    > function swapPic(layer,i mgName,imgObj) {[/color]

    Since you didn't tell, I'll try guessing what these arguments are.

    // layer - the name of a NS 4 layer if the image is inside one.
    // In general, there could be more than one layer, but in practice
    // it amost never happens.
    // imgName - the id of the image element to change.
    // imgObj - a string containing the name of a global variable.
    // A very inefficient way to do it. I'll change it to contain
    // the value of the variable instead.
    [color=blue]
    > o = (n &&
    > layer?document. layers[layer].document.image s[imgName]:document.image s[imgName]);[/color]

    Long line. Luckily neither your nor my newsreader automatically break
    lines.

    I *assume* that "n" is a global variable that is true if the browser
    is Netscape 4. It is not needed. I would make "o" a local variable instead
    of global.

    var o = (layer && document.layers && document.layers[layer])?
    document.layers[layer].document.image s[imgName]:
    document.images[imgName];
    [color=blue]
    > if(!o.hasswappe d) o.src = eval(imgObj+".s rc");[/color]

    If you are using eval, you are probably doing something wrong.

    if (!o.hasswapped) {o.src = imgObj.src;}
    [color=blue]
    > }[/color]
    [color=blue]
    > var oRef = null;
    >
    > var oRefImg = null;[/color]

    This is later used as the src property of an image, so a better name would
    be "oRefSrc".
    [color=blue]
    > function keepPic(layer,i mgName,imgObj) {
    > if(oRef) {
    > // swap image back
    > oRef.src = oRefImg;
    > }[/color]
    [color=blue]
    > if (document.image s) {[/color]

    Why check for document.images here, and not in the previous function.
    [color=blue]
    > o = (n &&
    > layer?document. layers[layer].document.image s[imgName]:document.image s[imgName]);[/color]

    As above.
    [color=blue]
    > if(o) {
    > oRef = o
    > oRefImg = o.src;
    > o.src = eval(imgObj+".s rc");[/color]

    o.src = imgObj.src;
    [color=blue]
    > o.hasswapped = true;
    > }
    > }
    > }[/color]
    [color=blue]
    > I use the following link to chose the image I want to display[/color]
    [color=blue]
    > <area shape="poly" alt="" coords="25,25,2 1,0,30,0"
    > href="javascrip t:void(0)" title=""
    > onMouseOver="sw apPic('metera', 'diala','img1') ;"[/color]

    onmouseover="sw apPic('metera', 'diala',img1)"

    No need to send a string containing 'img1' as an argument, if you
    just use it to look up the value of the variable of that name. Just
    send the value directly.
    [color=blue]
    > onClick="keepPi c('metera','dia la','img1');">[/color]

    onclick="keepPi c('metera','dia la',img1);">
    [color=blue]
    > <div id="metera"><im g src="images/pointer.aa.gif" alt="" name="diala"
    > id="diala" width="50" height="50" border="0" usemap="#dialit a"></div>[/color]

    /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

    • Richard Cornford

      #3
      Re: unusual behaviour

      "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
      news:smll1h3u.f sf@hotpop.com.. .[color=blue]
      > Ken Tuck <webmaster@eyec reate.net> writes:[/color]
      <snip>[color=blue][color=green]
      >> var oRefImg = null;[/color]
      >
      >This is later used as the src property of an image, so a better
      >name would be "oRefSrc".[/color]

      Or maybe sRefSrc if the value it is to hold is a string.

      <snip>[color=blue][color=green]
      >><area shape="poly" alt="" coords="25,25,2 1,0,30,0"
      >>href="javascr ipt:void(0)" title=""
      >>onMouseOver=" swapPic('metera ','diala','img1 ');"[/color]
      >
      > onmouseover="sw apPic('metera', 'diala',img1)"
      >
      >No need to send a string containing 'img1' as an argument, if you
      >just use it to look up the value of the variable of that
      >name. Just send the value directly.
      >[color=green]
      >> onClick="keepPi c('metera','dia la','img1');">[/color]
      >
      > onclick="keepPi c('metera','dia la',img1);">[/color]
      <snip>

      One of the (many) undesirable side effects of executing a javascript
      pseudo-protocol URL is that some browsers stop bothering to load image
      graphics after its use. Some, but not all, versions of IE exhibit that
      effect.

      The effect can probably be avoided by returning false from the onclick
      handler to cancel the navigation in the HREF, but that makes the
      javascript URL pointless as it will only be used (and predictably fail)
      in the event that JavaScript is unavailable on the browser.

      Richard.


      Comment

      Working...