Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with simple javascript

Status
Not open for further replies.

WalkieTalkie

Technical User
Feb 15, 2002
91
NZ
I am a complete newbie, in the final stages of my first web site. I have used FrontPage, and do not know much about code.

I have used the email encoder I found at to encode my email address to reduce the risk of spam. All working well. However, I want to change the font colour of the encoded bit, and can't for the life of me make it change! I know this must be really simple for anyone who knows anything about code. Can someone please help? The code I'm using is as follows:

Code:
<p align="left" style="margin-top:0; margin-bottom:0">
            
            <b><font face="Century Gothic" size="1" color="#990033"><script type="text/javascript">
//<![CDATA[
<!--
var x="function f(x){var i,o=\"\",ol=x.length,l=ol;while(x.charCodeAt(l/13)!" +
"=92){try{x+=x;l+=l;}catch(e){}}for(i=l-1;i>=0;i--){o+=x.charAt(i);}return o" +
".substr(0,ol);}f(\")34,\\\"YQ[v|c=tfy330\\\\000\\\\330\\\\u8:3<5ql120\\\\71" +
"0\\\\430\\\\700\\\\i'3f)-\\\"\\\\/$`Q_530\\\\XU_J030\\\\XB520\\\\_P[]sr\\\\" +
"r020\\\\IG^@\\\\\\\\700\\\\400\\\\y]QKTQq{=~~M$lts771\\\\vfa.ja bo%mgasjpwm" +
"m6#>220\\\\>6!'w#?& )*d130\\\\y%'3(730\\\\_100\\\\630\\\\320\\\\TU]C_GC530\\"+
"\\F_UB[NCO\\\"(f};o nruter};))++y(^)i(tAedoCrahc.x(edoCrahCmorf.gnirtS=+o;7" +
"21=%y;i=+y)34==i(fi{)++i;l<i;0=i(rof;htgnel.x=l,\\\"\\\"=o,i rav{)y,x(f noi" +
"tcnuf\")"                                                                    ;
while(x=eval(x));
//-->
//]]>
</script></font></b></p>

I figure it must be something to do with the <font> tags, and have tried shifting them all around, all to no avail. The user-side text still ends up black instead of maroon. What am I doing wrong? All offers of help gratefully received.
 
This is not really a javascript issue, but try doing it this way:

Code:
<p align="left" style="margin-top:0; margin-bottom:0; [red]color:#990033;[/red]">

I would also suggest you ditch the font tag altogether, and place the font and size definitions inside the <p> style.

Code:
<p align="left"; style="... font-family:'Century Gothic'; font-size:12px;" ...>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi Phil
Thanks for your reply, but I still can't make it work. I've tried it both ways, but maybe I'm not doing it right. All three ways end up showing the same - correct font and size, but wrong colour. Here's what I've tried:

Code:
<p align="left" style="margin-top:0; margin-bottom:0"; color="#990033">
			<b>
			<font color="#990033" face="Century Gothic" size="1">
			<script type="text/javascript">
//<![CDATA[
<!--
var x="function f(x){var i,o=\"\",l=x.length;for(i=l-1;i>=0;i--) {try{o+=x.c" +
"harAt(i);}catch(e){}}return o;}f(\")\\\"function f(x,y){var i,o=\\\"\\\\\\\""+
"\\\\,l=x.length;for(i=0;i<l;i++){y%=127;o+=String.fromCharCode(x.charCodeAt" +
"(i)^(y++));}return o;}f(\\\"\\\\MEHY@KAD\\\\\\\\037EA]AS[V\\\\\\\\021\\\\\\" +
"\\030\\\\\\\\007]\\\\\\\\035VM%'\\\\\\\\177\\\\\\\\037f('.$=%q%#( \\\\\\\\0" +
"20<%0;;%\\\\\\\\\\\"\\\\4-35;s=0N\\\\\\\\017\\\\\\\\030\\\\\\\\\\\\\\\\\\\\" +
"\\\\027\\\\\\\\020\\\\\\\\004\\\\\\\\r\\\\\\\\r\\\\\\\\n\\\\\\\\036V;\\\\\\" +
"\\010\\\\\\\\014O\\\\\\\\025\\\\\\\\037\\\\\\\\003\\\\\\\\006\\\\\\\\035\\\\"+
"\\\\007\\\\\\\\017+ZY\\\\\\\\016\\\\\\\\022\\\\\\\\010\\\\\\\\021\\\\\\\\03" +
"3=] @hlel(}e+\\\\\\\\177h`k0p|3qxw~t9nt<PI\\\\\\\\\\\\\\\\|\\\\\\\\003\\\\\\"+
"\\034FIDOK\\\\\\\\010d}h\\\\\\\\014\\\\\\\\021\\\\\\\\001N\\\\\\\\016\\\\\\" +
"\\023\\\\\\\\033\\\\\\\\010\\\\\\\\004\\\\\\\\016\\\"\\\\,41)\\\"(f};)lo,0(" +
"rtsbus.o nruter};)i(tArahc.x=+o{)--i;0=>i;1-l=i(rof}}{)e(hctac};l=+l;x=+x{y" +
"rt{)94=!)31/l(tAedoCrahc.x(elihw;lo=l,htgnel.x=lo,\\\"\\\"=o,i rav{)x(f noi" +
"tcnuf\")"                                                                    ;
while(x=eval(x));
//-->
//]]>
</script></font></b></p>



Code:
<p align="left" style="margin-top:0; margin-bottom:0"; font-color="#990033"; font-size="1"; font-family="Century Gothic">
			<b>
			<font color="#990033" face="Century Gothic" size="1">
			<script type="text/javascript">
//<![CDATA[
<!--
var x="function f(x){var i,o=\"\",l=x.length;for(i=l-1;i>=0;i--) {try{o+=x.c" +
"harAt(i);}catch(e){}}return o;}f(\")\\\"function f(x,y){var i,o=\\\"\\\\\\\""+
"\\\\,l=x.length;for(i=0;i<l;i++){y%=127;o+=String.fromCharCode(x.charCodeAt" +
"(i)^(y++));}return o;}f(\\\"\\\\MEHY@KAD\\\\\\\\037EA]AS[V\\\\\\\\021\\\\\\" +
"\\030\\\\\\\\007]\\\\\\\\035VM%'\\\\\\\\177\\\\\\\\037f('.$=%q%#( \\\\\\\\0" +
"20<%0;;%\\\\\\\\\\\"\\\\4-35;s=0N\\\\\\\\017\\\\\\\\030\\\\\\\\\\\\\\\\\\\\" +
"\\\\027\\\\\\\\020\\\\\\\\004\\\\\\\\r\\\\\\\\r\\\\\\\\n\\\\\\\\036V;\\\\\\" +
"\\010\\\\\\\\014O\\\\\\\\025\\\\\\\\037\\\\\\\\003\\\\\\\\006\\\\\\\\035\\\\"+
"\\\\007\\\\\\\\017+ZY\\\\\\\\016\\\\\\\\022\\\\\\\\010\\\\\\\\021\\\\\\\\03" +
"3=] @hlel(}e+\\\\\\\\177h`k0p|3qxw~t9nt<PI\\\\\\\\\\\\\\\\|\\\\\\\\003\\\\\\"+
"\\034FIDOK\\\\\\\\010d}h\\\\\\\\014\\\\\\\\021\\\\\\\\001N\\\\\\\\016\\\\\\" +
"\\023\\\\\\\\033\\\\\\\\010\\\\\\\\004\\\\\\\\016\\\"\\\\,41)\\\"(f};)lo,0(" +
"rtsbus.o nruter};)i(tArahc.x=+o{)--i;0=>i;1-l=i(rof}}{)e(hctac};l=+l;x=+x{y" +
"rt{)94=!)31/l(tAedoCrahc.x(elihw;lo=l,htgnel.x=lo,\\\"\\\"=o,i rav{)x(f noi" +
"tcnuf\")"                                                                    ;
while(x=eval(x));
//-->
//]]>
</script></b></p>
 
Hi

That JavaScript code is [tt]document.write()[/tt]ing an [tt]a[/tt] tag. If the [tt]a[/tt] tag's color is set by CSS ( the correct way ) or by [tt]body[/tt] tag's [tt]link[/tt]/[tt]vlink[/tt] attribute ( the deprecated way ), then setting the color for a parent tag leads nowhere.

Feherke.
 
Look back at what I set in red above. and compare it to what you have. notice I have no equal sign (its a colon) or quotes around the color value.

I tested it with your code, and it works when the style is correct.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Phil,
Thanks for your patience, and apologies for my lack of attention to detail. I've corrected my mistakes (see below) - but still no luck - the text comes out black.

Using <font> tags:
Code:
<p align="left" style="margin-top:0; margin-bottom:0;">
<b>
<font color="#990033" face="Century Gothic" size="1">
<script type="text/javascript">
//<![CDATA[
<!--
var x="function f(x){var i,o=\"\",l=x.length;for(i=l-1;i>=0;i--) {try{o+=x.c" +
"harAt(i);}catch(e){}}return o;}f(\")\\\"function f(x,y){var i,o=\\\"\\\\\\\""+
"\\\\,l=x.length;for(i=0;i<l;i++){y%=127;o+=String.fromCharCode(x.charCodeAt" +
"(i)^(y++));}return o;}f(\\\"\\\\MEHY@KAD\\\\\\\\037EA]AS[V\\\\\\\\021\\\\\\" +
"\\030\\\\\\\\007]\\\\\\\\035VM%'\\\\\\\\177\\\\\\\\037f('.$=%q%#( \\\\\\\\0" +
"20<%0;;%\\\\\\\\\\\"\\\\4-35;s=0N\\\\\\\\017\\\\\\\\030\\\\\\\\\\\\\\\\\\\\" +
"\\\\027\\\\\\\\020\\\\\\\\004\\\\\\\\r\\\\\\\\r\\\\\\\\n\\\\\\\\036V;\\\\\\" +
"\\010\\\\\\\\014O\\\\\\\\025\\\\\\\\037\\\\\\\\003\\\\\\\\006\\\\\\\\035\\\\"+
"\\\\007\\\\\\\\017+ZY\\\\\\\\016\\\\\\\\022\\\\\\\\010\\\\\\\\021\\\\\\\\03" +
"3=] @hlel(}e+\\\\\\\\177h`k0p|3qxw~t9nt<PI\\\\\\\\\\\\\\\\|\\\\\\\\003\\\\\\"+
"\\034FIDOK\\\\\\\\010d}h\\\\\\\\014\\\\\\\\021\\\\\\\\001N\\\\\\\\016\\\\\\" +
"\\023\\\\\\\\033\\\\\\\\010\\\\\\\\004\\\\\\\\016\\\"\\\\,41)\\\"(f};)lo,0(" +
"rtsbus.o nruter};)i(tArahc.x=+o{)--i;0=>i;1-l=i(rof}}{)e(hctac};l=+l;x=+x{y" +
"rt{)94=!)31/l(tAedoCrahc.x(elihw;lo=l,htgnel.x=lo,\\\"\\\"=o,i rav{)x(f noi" +
"tcnuf\")"                                                                    ;
while(x=eval(x));
//-->
//]]>
</script></font></b></p>


Using <p>style and no <font> tag:
Code:
<p align="left"; style="font-color:#990033; font-family:'Century Gothic'; font-size:8px;">
<b>
<script type="text/javascript">
//<![CDATA[
<!--
var x="function f(x){var i,o=\"\",l=x.length;for(i=l-1;i>=0;i--) {try{o+=x.c" +
"harAt(i);}catch(e){}}return o;}f(\")\\\"function f(x,y){var i,o=\\\"\\\\\\\""+
"\\\\,l=x.length;for(i=0;i<l;i++){y%=127;o+=String.fromCharCode(x.charCodeAt" +
"(i)^(y++));}return o;}f(\\\"\\\\MEHY@KAD\\\\\\\\037EA]AS[V\\\\\\\\021\\\\\\" +
"\\030\\\\\\\\007]\\\\\\\\035VM%'\\\\\\\\177\\\\\\\\037f('.$=%q%#( \\\\\\\\0" +
"20<%0;;%\\\\\\\\\\\"\\\\4-35;s=0N\\\\\\\\017\\\\\\\\030\\\\\\\\\\\\\\\\\\\\" +
"\\\\027\\\\\\\\020\\\\\\\\004\\\\\\\\r\\\\\\\\r\\\\\\\\n\\\\\\\\036V;\\\\\\" +
"\\010\\\\\\\\014O\\\\\\\\025\\\\\\\\037\\\\\\\\003\\\\\\\\006\\\\\\\\035\\\\"+
"\\\\007\\\\\\\\017+ZY\\\\\\\\016\\\\\\\\022\\\\\\\\010\\\\\\\\021\\\\\\\\03" +
"3=] @hlel(}e+\\\\\\\\177h`k0p|3qxw~t9nt<PI\\\\\\\\\\\\\\\\|\\\\\\\\003\\\\\\"+
"\\034FIDOK\\\\\\\\010d}h\\\\\\\\014\\\\\\\\021\\\\\\\\001N\\\\\\\\016\\\\\\" +
"\\023\\\\\\\\033\\\\\\\\010\\\\\\\\004\\\\\\\\016\\\"\\\\,41)\\\"(f};)lo,0(" +
"rtsbus.o nruter};)i(tArahc.x=+o{)--i;0=>i;1-l=i(rof}}{)e(hctac};l=+l;x=+x{y" +
"rt{)94=!)31/l(tAedoCrahc.x(elihw;lo=l,htgnel.x=lo,\\\"\\\"=o,i rav{)x(f noi" +
"tcnuf\")"                                                                    ;
while(x=eval(x));
//-->
//]]>
</script></b></p>

Any more help you can suggest is appreciated in advance.
 
Hi Feherke
Thanks for taking the time to reply. I'm sorry but I haven't a clue what you are talking about. As I said, I'm new at this. But I am keen to learn new stuff. I have not used CSS, (and I know this is something I should learn eventually), but in the meantime, if you have any suggestions that might fix this problem for me, I'd appreciate it!

Oh, and I'm sorry if this is in the wrong post - I tried first in the Web Designers' Forum, but was told it should be in the Javascript Forum. Would it be better posted in another different forum?

Miranda
 
Hi

Miranda said:
But I am keen to learn new stuff.
You should start with uninstalling FrontPage.
Miranda said:
I have not used CSS
Your original [tt]p[/tt] tag is styled with CSS. Yes, the [tt]style[/tt] attribute's value also contains CSS.

Without seeing your entire page, we can only make guesses. Please post a URL to publicly accessible copy of that page.


Feherke.
 
Here:

This complete thing works:

Code:
<p align="left"; style="color:#990033; font-family:'Century Gothic'; font-size:8px;">
            
            <b><script type="text/javascript">
//<![CDATA[
<!--
var x="function f(x){var i,o=\"\",ol=x.length,l=ol;while(x.charCodeAt(l/13)!" +
"=92){try{x+=x;l+=l;}catch(e){}}for(i=l-1;i>=0;i--){o+=x.charAt(i);}return o" +
".substr(0,ol);}f(\")34,\\\"YQ[v|c=tfy330\\\\000\\\\330\\\\u8:3<5ql120\\\\71" +
"0\\\\430\\\\700\\\\i'3f)-\\\"\\\\/$`Q_530\\\\XU_J030\\\\XB520\\\\_P[]sr\\\\" +
"r020\\\\IG^@\\\\\\\\700\\\\400\\\\y]QKTQq{=~~M$lts771\\\\vfa.ja bo%mgasjpwm" +
"m6#>220\\\\>6!'w#?& )*d130\\\\y%'3(730\\\\_100\\\\630\\\\320\\\\TU]C_GC530\\"+
"\\F_UB[NCO\\\"(f};o nruter};))++y(^)i(tAedoCrahc.x(edoCrahCmorf.gnirtS=+o;7" +
"21=%y;i=+y)34==i(fi{)++i;l<i;0=i(rof;htgnel.x=l,\\\"\\\"=o,i rav{)y,x(f noi" +
"tcnuf\")"                                                                    ;
while(x=eval(x));
//-->
//]]>
</script></font></b></p>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks again, Phil, but still no good. I've pasted your code into my page, replacing my code, and the text comes out blue now. I've also tried pasting your code straight into a new blank page, and its still blue.

Feherke, thanks for pointing out my ignorance again. I can't send you a link to my page because it isn't published yet.

Thanks anyway for trying - unless you can think of another way to fix this, I guess I'll have to go with black text.

Miranda
 
Ha ha - I've figured it out, after quite a bit of research!

There was a line in the body:
<body link="#000000" alink="#808080" vlink="#990033">
that was overiding the css style in the Head.

(I am guessing that because the email address was encoded, the css style did not apply because of the encoding - it looked like ordinary HTML, so the it followed the html rule #000000 (that's how I make sense of it, anyhow).

So, I changed it to:

<body link="#990033" alink="#808080" vlink="#990033">

and its all working fine! Only thing is that I can't make it change color when the mouse hovers over it, presumably because that's an attribute you have to set in css. I can live with that, though.

Sorry to confuse you and I hope you haven't wasted too much time on this. I, for one, have learned heaps of stuff through this so thank you for that.
Miranda
 
...and I can make it change color on hover-over too now. Yay!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top