Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Help to display javascript instead of execute

    I am trying to make an html page that lists all of the different javascripts that are useable in a game I play. I would like them to be in boxes with the select code option on the top. But with some of the javascript codes they have < in them. The problem is that when my html page says :
    Code:
    					<td colspan="5" rowspan="1" style="vertical-align: top;">
    						<dl class="codebox">
    							<dt>Target-URL: <a href="#" onclick="selectCode(this); return false;">SELECT ALL</a></dt>
    							<dd style="margin: 0px; padding: 0px;"><code>javascript:function V(){return 1;}window.onerror=V;function Z(){a=1.5;b=0.66666666666;c='{unit} from [village]{coords}[/village] ([player]{player}[/player]) is attacking'; p=['Scout','LC','HC','Axe','Sword','Ram','***Noble***'];d=document;function J(e){return/\s\(((\d+)\|(\d+))\)\sK/i.exec(e);}function K(e){f=parseInt(e,10);return(f>9?f:'0'+f);}function L(g,e){return g.getElementsByTagName(e);}function N(g){return g.innerHTML;}function M(g){return N(L(g,'a')[0]);}function O(){return k.insertRow(E++);}function W(f){return B.insertCell(f);}function P(g,e){g.innerHTML=e;return g;}function X(e){C=B.appendChild(d.createElement('th'));return P(C,e);}function Y(f){return K(f/U)+':'+K(f%(U)/T )+':'+K(f%T);}U=3600;T=60;R='table';S='width';s=L(document,R);for(j=0;j<s.length;j++){s[j].removeAttribute(S);if(s[j].className=='main'){s=L(L(s[j],'tbody')[0],R);break;}}D=0;for(j=0;j<s.length;j++){s[j].removeAttribute(S);if(s[j].className='vis'){k=s[j];if(t=k.rows)D=t.length;break;}}for(E=0;E<D;E++){l=t[E];m=(u=l.cells)?u.length:0;if(m){u[m-1].colSpan=5-m;if(N(u[0])=='Arrival:')Q=new Date(N(u[1]).replace(/<.*/i,''));else{if(N(u[0])=='Arrival in:')v=N(u[1]).match(/\d+/ig);}if(E==1)G=M(u[2]);if(E==2)w=J(M(u[1]));if(E==4)x=J(M(u[1]));}}y=v[0]*U+v[1]*T+v[2]*1;n=w[2]-x[2];o=w[3]-x[3];F=Math.sqrt(n*n+o*o);H=F.toFixed(2);E=D-2;s=L(k,'input');i=s[1];h=s[0];h.size=T;B=O();P(W(0),'Distance:').colSpan=2;P(W(1),H+' Fields').colSpan=2;B=O();X('Unit');X('Sent');X('Duration');X('Name to');c=c.replace(/\{coords\}/i,w[1]).replace(/\{distance\}/i,H).replace(/\{player\}/i,G);for(j in p){z=Math.round([9,10,11,18,22,30,35][j]*T*F/a/b);A=z-y;if(A>0){I=Y(z);B=O();P(W(0),p[j]);P(W(1),A<T&&'just now'||A<U&&Math.floor(A/T)+' mins ago'||Y(A)+' ago');P(W(2),I);C=W(3);q=C.appendChild(i.cloneNode(1));r=C.appendChild(h.cloneNode(1));r.id='I'+j;r.value=c.replace(/\{duration\}/i,I).replace(/\{sent\}/i,new Date(Q-z*1000).toLocaleString().replace(/.\d{4}/i,'').replace(/(\w{3})\w*/i,'$1')).replace(/\{unit\}/i,p[j]);q.onmousedown=new Function('h.value=d.getElementById(\'I'+j+'\').value;');}}}Z();</code></dd>
    						</dl>
    					</td>
    instead the page that is outputted has only

    Target-URL: SELECT ALL
    javascript:function V(){return 1;}window.onerror=V;function Z(){a=1.5;b=0.66666666666;c=' from [village][/village] ([player][/player]) is attacking'; p=['Scout','LC','HC','Axe','Sword','Ram','***Noble***'];d=document;function J(e){return/\s\(((\d+)\|(\d+))\)\sK/i.exec(e);}function K(e){f=parseInt(e,10);return(f>9?f:'0'+f);}function L(g,e){return g.getElementsByTagName(e);}function N(g){return g.innerHTML;}function M(g){return N(L(g,'a')[0]);}function O(){return k.insertRow(E++);}function W(f){return B.insertCell(f);}function P(g,e){g.innerHTML=e;return g;}function X(e){C=B.appendChild(d.createElement('th'));return P(C,e);}function Y(f){return K(f/U)+':'+K(f%(U)/T )+':'+K(f%T);}U=3600;T=60;R='table';S='width';s=L(document,R);for(j=0;j<.*/i,''));else{if(N(u[0])=='Arrival in:')v=N(u[1]).match(/\d+/ig);}if(E==1)G=M(u[2]);if(E==2)w=J(M(u[1]));if(E==4)x=J(M(u[1]));}}y=v[0]*U+v[1]*T+v[2]*1;n=w[2]-x[2];o=w[3]-x[3];F=Math.sqrt(n*n+o*o);H=F.toFixed(2);E=D-2;s=L(k,'input');i=s[1];h=s[0];h.size=T;B=O();P(W(0),'Distance:').colSpan=2;P(W(1),H+' Fields').colSpan=2;B=O();X('Unit');X('Sent');X('Duration');X('Name to');c=c.replace(/\{coords\}/i,w[1]).replace(/\{distance\}/i,H).replace(/\{player\}/i,G);for(j in p){z=Math.round([9,10,11,18,22,30,35][j]*T*F/a/b);A=z-y;if(A>0){I=Y(z);B=O();P(W(0),p[j]);P(W(1),A

    and then it stops.

    How can I get it to just see the < as a character to print instead of trying to read it as a code?

  • #2
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post
    You'll have to escape the < in your javascript as &lt;

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,448
    Thanks
    11
    Thanked 598 Times in 578 Posts
    you can put anything besides "</textarea>" inside a textarea, plus it's easy to selectAll that way...
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •