SitePoint Sponsor |
|
User Tag List
Results 1 to 10 of 10
-
Jan 9, 2007, 21:05 #1
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
-
Jan 10, 2007, 07:20 #2
- 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); } } } }
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
-
Jan 10, 2007, 10:35 #3
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
-
Jan 10, 2007, 12:11 #4
- 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
-
Jan 10, 2007, 12:32 #5
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
-
Jan 10, 2007, 13:04 #6
- Join Date
- Dec 2006
- Location
- Prague
- Posts
- 210
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
-
Jan 10, 2007, 13:06 #7
- 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
-
Jan 10, 2007, 15:42 #8
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
-
Jan 10, 2007, 20:16 #9
- Join Date
- Oct 2004
- Location
- Troy, Mi
- Posts
- 231
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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'; }
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>
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.
-
Jan 10, 2007, 20:24 #10
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.
Bookmarks