strange syntax

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

strange syntax

Post by Luke »

I often find code like this...

Code: Select all

<script	type="text/javascript">
if(ns4)_d.write("<scr"+"ipt type=text/javascript src=../menu/mmenuns4.js><\/scr"+"ipt>");		
  else _d.write("<scr"+"ipt type=text/javascript src=../menu/mmenudom.js><\/scr"+"ipt>"); 
</script>
Why the "<scr" + "ipt" ??

Am I missing something? I don't get it.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

because it's being written out with javascript, it's to not confuse the 'real' script tags with the ones being written.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

You can just remove the + and surround your javascript (inside the script tags) with "<![CDATA[" and "]]>". This will tell the browser the contents of CDATA are literal characters not to be interpreted as markup.
Post Reply