www.webdeveloper.com
Results 1 to 7 of 7

Thread: Help with a Javascript that works in almost all browser but IE

  1. #1
    Join Date
    Jan 2006
    Posts
    4

    Help with a Javascript that works in almost all browser but IE

    I have a javascript that works fine in almost every browsers with the exception of IE. the script is a function that allows you to click on a thumbnail and it loads the image by replacing an image. Does any one have an idea about how to get it to work in IE?

    http://angryteeth.net/gallery.shtml

    in the head:
    <!--

    function MM_findObj(n, d) { //v4.0
    var p,i,x;

    if(!d) d=document;

    if((p=n.indexOf("?"))>0&&parent.frames.length)
    {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
    }

    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && document.getElementById) x=document.getElementById(n);
    return x;
    }

    function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;

    for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null)
    {
    document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
    }
    }

    -->

    in the body:

    <td><a href="javascript:;" onclick="MM_swapImage('largeimg','','img/.../2.jpg',1)"><img src="img/.../2thumb.jpg" name="defeat" border="0" height="50" width="50" alt=""></a></td>

    Thanks

  2. #2
    Join Date
    Dec 2005
    Location
    FL, USA
    Posts
    265
    Seems lite the code is made by a program - and those usually make sure that the script works everywhere. Are you sure you didn't change anything in the code?
    Am I a moderator?
    Well, what function are you going to use to find out?

  3. #3
    Join Date
    Aug 2005
    Location
    The Hill Ch' Hill
    Posts
    381

    Lightbulb Use a better version

    Here Take an early working of my code. Should be simple enough to implement.
    and works on all modern browsers... as I remember

    ----------------------------------------------------------------------
    put between <head>........</head> in HTML code.


    <script type="text/javascript">
    window.onload=function() {
    sourceImg=document.getElementById("source");

    imgs=document.getElementsByTagName("img");
    for (var i=0; i<imgs.length; i++){
    if (imgs[i].getAttribute("name") == "linked"){
    imgs[i].onclick=function() {
    sourceImg.src=this.src;
    }
    imgs[i].style.cursor="hand";
    }
    }
    }
    </script>



    change the "link images" to the thumbnails and "source image" to your initial image


    <body>
    <!-- link images -->
    <img name="linked" src="imgs/1.jpg"></img>
    <img name="linked" src="imgs/2.jpg"></img>
    <img name="linked" src="imgs/3.jpg"></img>
    <img name="linked" src="imgs/4.jpg"></img>

    <!-- source image -->
    <img id="source" src="sourceImg.jpg"></img>

    </body>

    When you have eliminated the impossible, whatever remains, however improbable, must be the truth !


    [Sir Arthur Conan Doyle]

  4. #4
    Join Date
    Dec 2005
    Location
    Queen Creek, AZ
    Posts
    1,564
    Use this set of functions instead:

    Code:
    function FP_swapImg() {//v1.0
     var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
     n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
     elm.$src=elm.src; elm.src=args[n+1]; } }
    }
    
    function FP_preloadImgs() {//v1.0
     var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
     for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
    }
    
    function FP_getObjectByID(id,o) {//v1.0
     var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
     else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
     if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
     for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
     f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
     for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
     return null;
    }
    Design first! Code later!

  5. #5
    Join Date
    Jan 2006
    Posts
    4
    Quote Originally Posted by CrazyMerlin
    Use this set of functions instead:

    Code:
    function FP_swapImg() {//v1.0
     var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
     n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
     elm.$src=elm.src; elm.src=args[n+1]; } }
    }
    
    function FP_preloadImgs() {//v1.0
     var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
     for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
    }
    
    function FP_getObjectByID(id,o) {//v1.0
     var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
     else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
     if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
     for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
     f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
     for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
     return null;
    }
    What do you use for your call line? I tried editing my <a href="javascript:;" onclick... line to match your code, but I must be missing something.

  6. #6
    Join Date
    Dec 2005
    Location
    Queen Creek, AZ
    Posts
    1,564
    simply change your: onclick="MM_swapImage('largeimg','','img/.../2.jpg',1)"

    to: onclick="FP_swapImg(1,0,/*id*/'largeimg',/*url*/'img/.../2.jpg');"
    Design first! Code later!

  7. #7
    Join Date
    Jan 2006
    Posts
    4
    Be patient with me I'm an artist learning web design so it may take me a min to understand.

    I copied the main js into a .js doc right from your post, as I did with my other code.

    and call it in the html

    <SCRIPT LANGUAGE="JavaScript" SRC="js-imgnavtest.js">
    </SCRIPT>

    I know the *ID* usualy means that I am supose to replace it with the ID I am using, but the script I was using before didn't use an ID. It just used the name=""

    I created a test page http://www.angryteeth.net/gallerytest.shtml

    <a href="javascript:;" onclick="FP_swapImg(1,0,/'limg',/'largeimg',/'img/.../left.jpg');"><img src="img/.../leftthumb.jpg" name="foot" border="0" height="50" width="50"></a>

    which is supose to swap the image in

    <td><div align="center"><img src="img/.../cedar.jpg" name="largeimg" id="limg"></div></td>

    I kind of guessed and added the id, id="limg", into this tag, but that doesn't seem to be what it wanted. Where should the id be placed?

    Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.11859 seconds
  • Memory Usage 2,913KB
  • Queries Executed 13 (?)
More Information
Template Usage (34):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (7)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates