Javascript won't work in Firefox

Discussion in 'Javascript' started by LAshooter, Jun 27, 2005.

  1. LAshooter

    LAshooter Guest

    I'm trying to use a javascript function that works in IE but not in Firefox.
    Is there something about this code that is IE specific? If so, can I
    add/alter something to make it work in more browsers?


    Ex:<img src="thumbs/Dina.jpg" alt="Dina Marie Vannoni" width="39"
    height="50" border="1" onClick="enlarge()"><script language="JavaScript">
    function enlarge() {
    oSrcElem = event.srcElement;
    imgLarge.src = oSrcElem.src.replace(/thumbs/,'images');
    }
    </script>
    Thanx,Wm(replies CC: to sdshooter at hotmail appreciated!)
     
    LAshooter, Jun 27, 2005
    #1
    1. Advertising

  2. LAshooter

    RobG Guest

    LAshooter wrote:
    > I'm trying to use a javascript function that works in IE but not in Firefox.
    > Is there something about this code that is IE specific? If so, can I
    > add/alter something to make it work in more browsers?


    Yes, and yes.

    >
    >
    > Ex:<img src="thumbs/Dina.jpg" alt="Dina Marie Vannoni" width="39"
    > height="50" border="1" onClick="enlarge()"><script language="JavaScript">


    The language attribute is depreciated, type is required.

    > function enlarge() {
    > oSrcElem = event.srcElement;


    Your use of 'event' here is the issue. IE uses a global 'event' that
    is always available, Geko browsers don't. Depending on how you attach
    your onclick, you may have to pass 'event' to the function. Then there
    are a few things you need to do in the function to tidy-up.

    ... onClick="enlarge(event)">
    <script type="text/javascript">
    function enlarge(e) {
    e = e || window.event; // fits both event models
    var oSrcElem = e.target || e.srcElement; // fits both IE & others

    > imgLarge.src = oSrcElem.src.replace(/thumbs/,'images');


    where does 'imgLarge' come from? If it's the id of an image element,
    then it will work in IE 'cos it uses ids as global variables, but...

    Other browsers don't. You could use the images collection but you'll
    probably settle for getElementById.

    You may want to look at the group FAQ for how to support older IE and
    document.all:

    <URL:http://www.jibbering.com/faq/#FAQ4_15>

    > }
    > </script>
    > Thanx,Wm(replies CC: to sdshooter at hotmail appreciated!)


    What's said in the group stays in the group...

    >
    >



    --
    Rob
     
    RobG, Jun 27, 2005
    #2
    1. Advertising

  3. Danny wrote:

    > Well, yes, srcElement is IE, mozilla uses .target, same object really,
    > now, you don't need it though, as you're using an event handler on the
    > actual element explicitly as opposed to binding it through its hierarchy,
    > so, instead, use:
    >
    > function enlarge(el) {
    > el.src=el.src.replace(/thumbs/,'images')
    > }
    >
    > onclick="enlarge(this)"


    This is error-prone and does not degrade cleanly.

    1. Having Thumbnails in a sibling directory is hardly good resource
    management. Thumbnails should be located in a subdirectory or
    (even better) in the same directory with slightly different
    filenames.

    2. What if a filename contains `thumbs'?

    3. What if the replace() method or RegExp literals are not supported
    accordingly?

    4. What if the element is clicked twice?

    5. What about users that don't have or don't want to use a pointing device?

    6. What about users with client-side scripting disabled or just not
    available?

    > On Sun, 26 Jun 2005 18:04:35 -0700, LAshooter <>
    > wrote:
    > [...]


    Please stop top-posting, and please stop cross-posting without Followup-To.
    <http://jibbering.com/faq/>


    PointedEars
     
    Thomas 'PointedEars' Lahn, Jul 14, 2005
    #3
  4. JRS: In article <>, dated Thu, 14 Jul
    2005 18:53:58, seen in news:comp.lang.javascript, Thomas 'PointedEars'
    Lahn <> posted :

    > please stop cross-posting without Followup-To.
    ><http://jibbering.com/faq/>


    Ignore the ramblings of this juvenile control freak. He has a Fuhrer-
    complex.

    I see nothing in the newsgroup FAQ about cross-posting of follow-ups,
    and I know of no such requirement in general Usenet standards.

    However, it is generally considered rude to set follow-up without
    explicitly saying so in the body of the article.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr John Stockton, Jul 14, 2005
    #4
  5. LAshooter

    Randy Webb Guest

    Thomas 'PointedEars' Lahn wrote:

    > Please stop top-posting, and please stop cross-posting without Followup-To.
    > <http://jibbering.com/faq/>


    And this coming from someone who set the follow-up to a newsgroup that
    is of questionable integrity/quality over a newsgroup that is chartered,
    the *official* (J)ava/ECMAScript newsgroup, and proven to be of quality
    and integrity?
    WOW.
    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
     
    Randy Webb, Jul 15, 2005
    #5
  6. Dr John Stockton wrote:

    > JRS: In article <>, dated Thu, 14 Jul
    > 2005 18:53:58, seen in news:comp.lang.javascript, Thomas 'PointedEars'
    > Lahn <> posted :
    >
    >> please stop cross-posting without Followup-To.
    >><http://jibbering.com/faq/>

    >
    > Ignore the ramblings of this juvenile control freak. He has a Fuhrer-
    > complex. [...]


    Ahh, eventually you do show your true face.

    Godwin's Law. You lose.



    PointedEars
     
    Thomas 'PointedEars' Lahn, Jul 15, 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. Chad
    Replies:
    4
    Views:
    8,339
  2. Altman
    Replies:
    2
    Views:
    862
    Altman
    Feb 14, 2007
  3. Nathan Sokalski

    Why won't the following work in FireFox?

    Nathan Sokalski, Oct 17, 2007, in forum: ASP .Net
    Replies:
    11
    Views:
    2,044
    David Mark
    Oct 18, 2007
  4. LRW
    Replies:
    5
    Views:
    122
    Dr John Stockton
    Dec 3, 2004
  5. Igal

    javascript won't work with FireFox

    Igal, Jan 22, 2007, in forum: Javascript
    Replies:
    3
    Views:
    103
Loading...

Share This Page