Closed Thread Icon

Topic awaiting preservation: InnerHTML equivalent for Mozilla? (and many more JS questions) (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8831" title="Pages that link to Topic awaiting preservation: InnerHTML equivalent for Mozilla? (and many more JS questions) (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: InnerHTML equivalent for Mozilla? (and many more JS questions) <span class="small">(Page 1 of 1)</span>\

 
Alevice
Paranoid (IV) Inmate

From: Mexico
Insane since: Dec 2002

posted posted 08-22-2003 23:25

1.Well, as I mentioned here, I found out that Mozilla cannot edit the content of a tag with a innerHTML property (seeing how that seems exclusive of IE, and probably opera).

I read somewhere that there was a similar method for it for NS (i assumed that would work for mozilla as well), but take a guess. Yes, it didnt.

My code was as follows:

code:
function changeContent(what,text) {
if (document.all)
what.innerHTML = text;
else if (document.layers) {
what.document.open();
what.document.write(text);
what.document.close();
}
}


As i said, over IE and Opera works just fine, which makes me think the second part of the script (the 'else') is just wrong.

Any other method to do it? Or some typo/mistake/whatever around that i cant seem to notice?

2. Another problem (well, not exactly a problem, just a mess with code) i have i that there could be a way to simplify something like this:

code:
var description = new Array(); //An array for putting the content. Just in case i dont rememebr what is this.
description[0] = " ";
description[1] = "One laaaaarge bunch of urls ";

description[2] = "Another laaaaarge bunch of urls";

description[3] = "And yet another laaarge bunch of urls";


EDIT: Code modified for the sake of forum's friendliness.

In case you have not figured out, this is the array i use for the function above (check the link i gave on the beginning for further information), but as you can see, each string is rather large, clunky and very messy to edit. Is there a way to generate this same content in a shorter and/or cleaner way?

3. Hiding layers elements. Again, this one i cant get it to work over Mozilla. I even read the faq here about it, but didnt work.

code:
var visiblelay=false;

function HiddenWindow(name)
{
if(document.getElementById)
{
if(visiblelay)
{ eval('document.all.'+name+'.style.visibility = "hidden"'); visiblelay = false; }
else
{ eval('document.all.'+name+'.style.visibility = "visible"'); visiblelay = true; }
}
else
{
if(visiblelay)
{ eval('document.all.'+name+'.visibility = "hide"'); visiblelay = false; }
else
{ eval('document.all.'+name+'.visibility = "show"'); visiblelay = true; }
}
}



My, i really suck coding.

Thanks in advance.

__________________________________


Alevice's Media Library

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 08-23-2003 17:31

Stop treating Mozilla like Netscape 4.x because their completely different! I probably shouldn?t have to say this, but I will because I?ll assume you haven?t done it yet -- go to the Mozilla home page and read the documentation, there's lots of info on the Mozilla DOM there. ( www.mozilla.org )

innerHTML does work for Mozilla (Netscape 6+) as does myObj.visibility = "hide" or "show".

And why are you using so many eval statements, their completely unnecessary and will slow down the code... You also check for document.getElementById, then you use document.all, in both cases? Try this in both IE and Mozilla: document.getElementById(stringID).style.visibility = "hide" (or = "show")

This is a prime example why you should NEVER do browser based checks in your code. Always check against the object you which to use like: if (myObj.innerHTML) then code?. instead of if (docment.all) then code?. as this will simply cause havoc in the long run (or the immediate as it is with your code) as browsers change, new browser hit the market and as bugs in existing browsers are fixed, your code, along with your web pages, will simply fall apart.

As for a way to simplify that array, try not putting so much crap in it. Or maybe you could break it down onto separate lines using the ?+? concatenate operator to join multiple strings across several line breaks like so:

myString = ?My string starts here, ? +
?then we have some more of the same string, ? +
?and now we?ll end the strings on this line.?;


Oh and everyone "sucks" at coding, some just have more practice under their belts that others do. At least, it's less disheartening to think of it that way.

Edit: For the sake of readability, would you mind remove the [ code ] tags from your post, they cause more harm than good anyways because they actually make it a nightmare to copy and past text from the fourm, so it's best to leave them unless the code breaks big time without the whitespace formatting. =)



[This message has been edited by Dracusis (edited 08-23-2003).]

HZR
Bipolar (III) Inmate

From: Cold Sweden
Insane since: Jul 2002

posted posted 08-23-2003 19:15
quote:
innerHTML does work for Mozilla (Netscape 6+) as does myObj.visibility = "hide" or "show".

No, "visible" or "hidden" works, although I'm pretty sure that's what you meant.

Veneficuz
Paranoid (IV) Inmate

From: A graveyard of dreams
Insane since: Mar 2001

posted posted 08-23-2003 22:17

A nice place to learn some more about JS is Slime's Enhancing Web Pages with JavaScript. A great introduction to js and DOM.

<--- yay! Post 1k

_________________________
"There are 10 kinds of people; those who know binary, those who don't and those who start counting at zero"

[This message has been edited by Veneficuz (edited 08-23-2003).]

Alevice
Paranoid (IV) Inmate

From: Mexico
Insane since: Dec 2002

posted posted 08-24-2003 00:55

Drac - as HZR said, innerhtml does not work for mozilla, as my prev version of that script was merely a 'onclick = obj.innerhtml ="stuff";' on the divs, and it did not work over mozilla, as Dl-44 can confirm.

For some reason, i cant get to work the getelementbyID (strange, coz i have already made scripts with it, i just forgot it for this one ). I will be posting it later.

Thanks for the idea for the strings. It worked excellent

Veneficuz - thanks for the link. I am checking it right now.

__________________________________


Alevice's Media Library

HZR
Bipolar (III) Inmate

From: Cold Sweden
Insane since: Jul 2002

posted posted 08-24-2003 01:11
quote:
Drac - as HZR said, innerhtml does not work for mozilla


Ehh, when did I say that? innerHTML works in Mozilla, yes.

Alevice
Paranoid (IV) Inmate

From: Mexico
Insane since: Dec 2002

posted posted 08-24-2003 01:53

Well, i still cant get it to work

Bah.

__________________________________


Alevice's Media Library

kuckus
Bipolar (III) Inmate

From: Berlin (almost)
Insane since: Dec 2001

posted posted 08-24-2003 08:56

Alevice - it works when you use document.getElementById to get the object:

document.getElementById("obj").innerHTML = "stuff";

The reason why obj.innerHTML doesn't work in Mozilla is that it implies document.all.obj.innerHTML which is the IE-only way of getting a reference to an element.

Alevice
Paranoid (IV) Inmate

From: Mexico
Insane since: Dec 2002

posted posted 09-01-2003 00:51

Hello all,

pardon for the delay, but i kept lookin and messin with no satisfactory results. Well, only one. By accident, i found that mozilla has a js console, which tells me my object ('test' in this case) is not defined. Obviously, it is (else it would not even work in IE), so i tried modifying the function call ( onclick="changeContent(test,description[5]);" turned into onclick="changeContent('test',description[5]);" ), but still, no luck at all (the single quoted version does not even work in IE).

So i guess there must be another way. Any pointers?

If it helps, dis the url: http://www.freewebs.com/alevice/LinkList.html

__________________________________


Alevice's Media Library

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 09-01-2003 01:27

I am going to have to assume that Kuckus post right above yours actually gives you your answer.

Of course, it is also what Dracusis and HZR said up above.....

trib
Paranoid (IV) Inmate

From: Den Haag, Netherlands
Insane since: Sep 2002

posted posted 09-01-2003 09:53

I keep posting this guys site because it's one of the handiest tools I know for quick reference ... don't open an editor without it ...
http://www.xs4all.nl/~ppk ... and especially
http://www.xs4all.nl/~ppk/js/index.html - the javascript/DHTML/DOM pages http://www.xs4all.nl/~ppk/css2tests/ - the CSS test pages


Bug-free software only exisits in two places
A programmer's mind and a salesman's lips

Alevice
Paranoid (IV) Inmate

From: Mexico
Insane since: Dec 2002

posted posted 09-04-2003 01:26

DL - Thats not quite what i asked. As i said, my problem was that 'test' (my div where i write the stuff) was not supposedly defined, according to my moz browser. Then again, my method was a bit wrong.

Trib - Thanks for the site. It provided me the correct code.

My original code was:

code:
function changeContent(what,text) {
if (what.innerHTML) {
what.innerHTML = text;
}
else if (document.all.getElementById(what).innerHTML) {
document.all.getElementById("what").innerHTML = text;
}
}



Which was not working, as i needed to quote the id over the getElementById method. It could have worked the eval function, but with the code provided over the site, i realize it was not necesary =P

Thanks so much you all, as you have provided me with more information than you think =)

__________________________________


Alevice's Media Library

« BackwardsOnwards »

Show Forum Drop Down Menu