Image border width not working in Safari

Discussion in 'JavaScript' started by cigi, Sep 20, 2008.

  1. #1
    Hi Guys

    The below code does not work in Safari, seems fine in IE. The code should change the image border width when you click the link.


    <script type="text/javascript">
    <!--
    function MM_changeProp(objId,x,theProp,theValue) { //v9.0
    var obj = null; with (document){ if (getElementById)
    obj = getElementById(objId); }
    if (obj){
    if (theValue == true || theValue == false)
    eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
    }
    }
    //-->
    </script>
    </head>

    <body>
    <p onclick="MM_changeProp('img','','borderWidth','10','IMG')">Link</p>
    <p><img src="image1.gif" name="img" width="1" height="10" border="0" id="img" /></p>
    </body>
    </html>

    Can anyone see why it's not working in Safari?

    Thanks for your help.

    cigi
     
    cigi, Sep 20, 2008 IP
  2. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Hi cigi,

    I don't have Safari, so I cannot check. So I guess... Either Safari doesn't like "with" statement, so try it with document.getElementById(objId);
    ... and if no success, then another thing might be the eval! so try this syntax obj.style[theProp] = theValue; (of course without eval)

    Does something work??
     
    lp1051, Sep 20, 2008 IP
  3. cigi

    cigi Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Many thanks for your reply lp1051 :D

    I ditched that idea and used this instead:

    function changeIt(){
    var width=1
    var height=18

    document.sizer.width=width
    document.sizer.height=height

    Onclick with text link. It just controls a transparent gif to move a div tag down once clicked.

    Works in Safari.

    cigi
     
    cigi, Sep 20, 2008 IP