SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru htown's Avatar
    Join Date
    Mar 2005
    Posts
    671
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    set the text of a layer with Javascript not wotrking in IE

    I am using DW8 and using the "Set Text of Layer" function which I have used on several occasions but for some reason it fails to work in IE6. IE7 and FF it works fine.

    I am not a Javascript programmer so I could use some assistance if anyone has an idea.

    You can see what I am doing at this web site.

    Thank You,
    Houston
    Houston Brown
    Split Light Designs
    Bringing your ideas to light.

  2. #2
    SitePoint Addict jtrelfa's Avatar
    Join Date
    Oct 2004
    Location
    Troy, Mi
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While I'm not fond of the implementation - I've taken a look at the code and it seems to work fine in IE - but only after I added some brackets and such to clean up the code and make it readable:
    Code:
    function MM_findObj(n, d) { //v4.01
      var p,i,x;
      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 && d.getElementById) {
        x = d.getElementById(n);
      }
      return x;
    }
    
    function MM_setTextOfLayer(objName,x,newText) { //v4.01
      if ((obj = MM_findObj(objName)) != null) {
        with (obj) {
          if (document.layers) {
            document.write(unescape(newText));
            document.close();
          } else {
            innerHTML = unescape(newText);
          }
        }
      }
    }
    I also added some 'alt' text to the image code to try and get a better visual of what was being set as the data in the DIV - that helped a lot, too.

    Whatever the case, I hope this helps a little. I've always found it best to take a close look at what the code is doing and insert a few debugging statements to see what values are being passed around.

    Also, I hate how DW switches back and forth between the options curly braces - makes for harder-to-read code IMO

  3. #3
    SitePoint Guru htown's Avatar
    Join Date
    Mar 2005
    Posts
    671
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I have replaced the code with what you sent me and it is still not working. I am testing this in IE6 (Works fine in IE7 and FF). I am using a copy of IE6 and I am not sure if that has anything to do with the problem or not. When I load, IE asks me twice if I want to "continue loading the content of this page?" I assume it is because of the flash.

    If you are not fond of this method, what would you suggest. I like the the idea that I am using the same window as I did not want to show the decks stacked in on top of each other but rather one at a time. I am ope to any suggestions that you might have.

    Thank you so much for your help.

    Houston
    Houston Brown
    Split Light Designs
    Bringing your ideas to light.

  4. #4
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try just moving backgrund, it is better, because you dont have to wait on pictures loading. I upload test here http://jiko.cz/deck/ you have to just make better picture, maybe with less collors, cause now is that one moving jpg image bigger than 7 png. This should works also without js Image is here http://jiko.cz/deck/deck.jpg

  5. #5
    SitePoint Guru htown's Avatar
    Join Date
    Mar 2005
    Posts
    671
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand the concept of moving the background, I am not sure I understand how to move the background when something is clicked on a div located somewhere else?

    Can you lend some assistance on that one?

    Thanks
    Houston Brown
    Split Light Designs
    Bringing your ideas to light.

  6. #6
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow

    function sw(){ //name of function
    m=document.getElementById('Map'); //id of map
    ar=m.getElementsByTagName('area'); // areas in map
    for(var i=0;i<ar.length;i++){ //makes array from areas in map
    ar[i].setAttribute('rel',i); //set numebred attribute to each tag area, start 0
    ar[i].onclick=function(){ //each area onclick do function
    n=this.getAttribute('rel'); //get this attribute rel = number
    document.getElementById('deckplan').style.backgroundPosition='0 -'+n*156+'px';
    //set backround position onclick, so
    // 0 -(0*156) => background-position:0 0;
    // 0 -(1*156) => background-position:0 -156;
    return false; // this will say browser do not use href, take click instead
    }
    }
    }
    if(document.childNodes){window.onload=sw};// onload load function if browser know childnodes, ussualy newer browser

  7. #7
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I forget
    document.getElementById('deckplan').style.backgroundPosition

    say on which element it will be aplicated, so here element with id deckplan

  8. #8
    SitePoint Guru htown's Avatar
    Join Date
    Mar 2005
    Posts
    671
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have this line elsewhere in your original code with some added coding at the end. Does this code need to go in there twice?
    Code:
     document.getElementById('deckplan').style.backgroundPosition
    Houston Brown
    Split Light Designs
    Bringing your ideas to light.

  9. #9
    SitePoint Addict jtrelfa's Avatar
    Join Date
    Oct 2004
    Location
    Troy, Mi
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by htown View Post
    If you are not fond of this method, what would you suggest. I like the the idea that I am using the same window as I did not want to show the decks stacked in on top of each other but rather one at a time. I am ope to any suggestions that you might have.
    If moving the background image isn't working, I would also suggest that you hide/show a different <div> element depending on what's clicked:
    Javascript:
    Code:
    function toggleDiv(elem) {
      var divs = document.getElementById('deckplan').getElementsByTagName("div");
      for (var i = 0; i < divs.length; i++) {
        divs[i].className = "invisible";
      }
      document.getElementById(elem).className = 'visible';
    }
    And then in your page, you have:
    HTML Code:
    <style type="text/css">
    .invisible {
      display:none;
    }
    .visible {
      display:block;
    }
    </style>
    <div id="deckplan">
      <div id="moonlight" class="visible"><insert image here></div>
      <div id="sun" class="invisible"><insert image here></div>
      ...
      <div id="columbus" class="invisible"><insert image here></div>
    </div>
    Then your link trigger: "toggleDiv('moonlight');" to hide the others and show the one you want.

    Just a suggestion - probably not the most elegant - but it's "another way to skin a cat". There's a ton of ways to do it..I just don't recommend the built-in Macromedia code because it's hard to troubleshoot and adds lots of inline events.

  10. #10
    SitePoint Guru htown's Avatar
    Join Date
    Mar 2005
    Posts
    671
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    jtrelfa,
    Thanks for following up again. Actually I like both solutions and they both seem to be pretty light code. DW also has the ability to impliment this code through a behavior. I know you are not fond of it, but since I dont know Jack about JS I go with what works.

    You code seems pretty strait forward so i think I will give it a shot.

    Thanks again.
    Houston Brown
    Split Light Designs
    Bringing your ideas to light.


Bookmarks

Posting Permissions

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