/    Sign up×
Community /Pin to ProfileBookmark

My code:

[code]
<script type=”text/javascript”>

window.onload = function () {

var el = document.getElementsByTagName(‘pre’)[0];
el.style.fontSize =”16px”;
// el.style.backgroundColor =”aqua”;

el.innerHTML = el.innerHTML.replace(/&lt;/g,”<font color=blue><b><</b></font>”) ;
el.innerHTML = el.innerHTML.replace(/&gt;/g,”<font color=blue><b>></b></font>”) ;

el.innerHTML = el.innerHTML.replace(/(text)(/)(javascript)/g,”<font color=pink>$1$2$3</font>”) ;

el.innerHTML = el.innerHTML.replace(/function/g,”<font color=blue><b>function</b></font>”) ;

el.innerHTML = el.innerHTML.replace(/{/g,”<font color=deeppink><b>{</b></font>”) ;
el.innerHTML = el.innerHTML.replace(/}/g,”<font color=deeppink><b>}</b></font>”) ;

el.innerHTML = el.innerHTML.replace(/var/g,”<font color=red>var</font>”) ;
el.innerHTML = el.innerHTML.replace(/el/g,”<font color=lime>el</font>”) ;
el.innerHTML = el.innerHTML.replace(/ ;/g,”<font color=blue><b> ;</b></font>”) ;

el.innerHTML = el.innerHTML.replace(/(/g,”<font color=gold>(</font>”) ;
el.innerHTML = el.innerHTML.replace(/)/g,”<font color=gold>)</font>”) ;

el.innerHTML = el.innerHTML.replace(/’/g,”<font color=lime><b>'</b></font>”) ;

el.innerHTML = el.innerHTML.replace(/[/g,”<font color=skyblue><b>[</b></font>”) ;
el.innerHTML = el.innerHTML.replace(/]/g,”<font color=skyblue><b>]</b></font>”) ;

el.innerHTML = el.innerHTML.replace(/for/g,”<font color=deeppink><b>for</b></font>”) ;

el.innerHTML = el.innerHTML.replace(/(d)/g,”<font color=red>$1</font>”) ;
el.innerHTML = el.innerHTML.replace(/getElementsByTagName/g,”<font color=turquoise><b>getElementsByTagName</b></font>”) ;
el.innerHTML = el.innerHTML.replace(/innerHTML/g,”<font color=lightseagreen><b>innerHTML</b></font>”) ;

}

</script>
<body>

<pre>
&lt;script type=”text/javascript”&gt;

window.onload = function () {
var a = 5 ;
var i ;
var el = document.getElementsByTagName(‘body’)[0];
for(i = 0 ; i &lt; a ; i++)
{
el.innerHTML += i ;
}
}

&lt;/script&gt;

</pre>

</body>
[/code]

” wil be [color=yellowgreen][/color]
= wil be [color=blue]=[/color]
++ wil be [color=orange]++[/color]
+= wil be [color=orange]+=[/color]
How can I do? Thanks…

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FangFeb 11.2007 — el.innerHTML = el.innerHTML.replace(/"/g,"&lt;font color=lightgreen&gt;&lt;b&gt;"&lt;/b&gt;&lt;/font&gt;") ; // must be the first replace done!
el.innerHTML = el.innerHTML.replace(/[^+=w]=/g,"&lt;font color=blue&gt;&lt;b&gt; =&lt;/b&gt;&lt;/font&gt;") ; // exclude +, = and alphanumeric characters before =
el.innerHTML = el.innerHTML.replace(/+=/g,"&lt;font color=gold&gt;&lt;b&gt;+=&lt;/b&gt;&lt;/font&gt;") ;
Copy linkTweet thisAlerts:
@samanyoluauthorFeb 11.2007 — Fang,

Thanks... It worked very well on Internet Explorer 7.

= is [color=blue]=[/color] ( ie, Firefox, Opera)

+= is [color=gold]+=[/color] ( ie, Firefox, Opera)

" is [color=lightgreen]"[/color] ( ie)

if I don't cancel this:

el.innerHTML = el.innerHTML.replace(/"/g,"<font color=lightgreen><b>"</b></font>") ;

It appears like this on Firefox.

"blue"><script type=""pink">text/javascript""blue">>

window.onload = "blue">function "gold">("gold">) "deeppink">{

"red">var a = "red">5"blue"> ;

"red">var i"blue"> ;

"red">var "lime">el = document."turquoise">getElementsByTagName"gold">("lime">'body"lime">'"gold">)"skyblue">["red">0"skyblue">];

"deeppink">for"gold">(i = "red">0"blue"> ; i "blue">< a"blue"> ; i++"gold">)

"deeppink">{

"lime">el."lightseagreen">innerHTML += i"blue"> ;

"deeppink">}

"deeppink">}

"blue"></script"blue">>


It appears like this on Opera

"#0f000c"><script type=""#ffc0f0">text/javascript""#0f000c">>

window.onload = "#0f000c">function "#ffd0f0">("#ffd0f0">) "#ff0f00">{

"#ff0f00">var a = "#ff0000">5"#0f000c"> ;

"#ff0f00">var i"#0f000c"> ;

"#ff0f00">var "#0f000c">el = document."#40e0d0">getElementsByTagName"#ffd0f0">("#0f000c">'body"#0f000c">'"#ffd0f0">)"#0f000c">["#ff0000">0"#0f000c">];

"#ff0f00">for"#ffd0f0">(i = "#ff0000">0"#0f000c"> ; i "#0f000c">< a"#0f000c"> ; i++"#ffd0f0">)

"#ff0f00">{

"#0f000c">el."#20b2aa">innerHTML += i"#0f000c"> ;

"#ff0f00">}

"#ff0f00">}

"#0f000c"></script"#0f000c">>

I want

i++ will be i[color=blue]++[/color]

How can I do? Thanks...
Copy linkTweet thisAlerts:
@FangFeb 11.2007 — el.innerHTML = el.innerHTML.replace(/"/g,"&lt;font color=lightgreen&gt;&lt;b&gt;"&lt;/b&gt;&lt;/font&gt;") ; // [COLOR="Red"]must be the first replace done![/COLOR]
You should have been able to guess this one from the other examples:el.innerHTML = el.innerHTML.replace(/++/g,"&lt;font color=blue&gt;&lt;b&gt;++&lt;/b&gt;&lt;/font&gt;") ;
×

Success!

Help @samanyolu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...