Convert HTML to Javascript

[Total: 0    Average: 0/5]

This will conver raw html into javascript written text.

Head Code:

<SCRIPT LANGUAGE="JavaScript">
<!--Hide JavaScript from Java-Impaired Browsers
var ls="";
var dq='"';
var sq="'";
var rr="r";

function jsPars(){ 
	ls=document.isn.txt.value; 
	if (ls==""){  
		alert("I'm sorry.  I don't find any text pasted into the text window");  
	} 
	else{  
		htmlPar();  
	} 
}

function htmlPar(){ 
	document.isn.txt.value="Working......."; 
	pos=ls.indexOf(dq); 
	pos1=ls.indexOf(sq); 
	if ((pos>-1)&&(pos1>-1)){  
		reWrt();  
	} 
	if (pos>-1){  
		qt=sq;  
	} 
	else{  
		qt=dq;  
	} 
	while (ls.indexOf(rr)>-1){  
		lc=ls.indexOf(rr);  
		ls=ls.substring(0,lc)+" "+ls.substring(lc+1,ls.length);  
	} 
	nls="<SCRIPT LANGUAGE="+qt+"JavaScript"+qt+">"+rr +"<!-- Hide from JavaScript-Impaired Browsers"+rr +" 	document.write("+qt+ls.substring(0,36)+qt; 
	
	ls=ls.substring(36,ls.length); 
	lsl=ls.length 
		pp=50;  
		if (pp>lsl) {   
			pp=lsl;   
		} 
		while (lsl>0){  
			nls+="r +"+qt+ls.substring(0,pp)+qt;  
			ls=ls.substring(pp,lsl);  
			lsl=ls.length;  
		if (pp>lsl){   
			pp=lsl;   
		}  
	} 
	nls+=");"+rr+"// End Hiding -->"+rr+"</SC" +"RIPT>"; 
	document.isn.txt.value=nls+rr+"<!-- Size: "+nls.length +" bytes --> "+rr; 
}

function reWrt(){ 
	pos=-1; 
	while (ls.indexOf(dq)>-1){  
		lc=ls.indexOf(dq);  
		ls=ls.substring(0,lc)+sq+ls.substring(lc+1,ls.length);  
	} 
}

function iA(){ 
	this.length=iA.arguments.length; 
	for (var i=0;i<this.length;i++){  
		this[i]=iA.arguments[i]; 
	}
}

// End Hiding -->
</SCRIPT>

Body Code:

<FORM NAME="isn">
<TABLE BORDER=0 WIDTH=486>
<TR><TD>
<DIV ALIGN="center">
<INPUT TYPE="button" NAME="but" VALUE=" Submit When Your HTML Has Been Pasted Below " onClick="jsPars()">
</DIV>
<P>
<TEXTAREA NAME="txt" ROWS=20 COLS=75>
</TEXTAREA>
<p>
COMMENTS:
<br>
It can be a giant time-consumer to code up HTML to be written by a JavaScript. 
Why?  Because of the present limitations on string length readable by the compiler.  
You have to keep concatenating the lines with single or double quotes and plus signs.  
Unlike PERL, which permits a write literal until end write statement is encountered, 
every bit of the HTML has to be specified in the "document.write("text");" format when using 
JavaScript.<P>This little app is for the Web Developer who is doing his/her own developments 
in JavaScript.  It's designed specifically to make the task of writing HTML from JavaScripts 
less onerous.<P>To use it, simply paste your HTML into the window below and click the submit 
button.  So long as you have not <B>mixed</B> single and double quotes in your HTML, it'll do 
the job for you. For example, if you code your HTML with double quotes (&lt;BODY BGCOLOR="white"> or 
&lt;A HREF="file.htm">), it will return the JavaScript statement properly concatenated. 
Similarly, if you code your HTML with single quotes (&lt;BODY BGCOLOR='white'> 
or &lt;A HREF='file.htm'>), it will function properly.<P>If you write JavaScript within 
JavaScript, this utility will also be useful, but you will need to split any &lt;/SCRIPT> 
calls like this:<P><DD><B>document.write("&lt;/SCR"+<DD>"IPT>"</B><P>to avoid "confusing" the 
compiler. (Either that or add some exception handling to the source code of this 
utility)


</TD></TR>
</TABLE>
</FORM>

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *