HTML code escaping to JS, often encounter problems, this code to achieve HTML and JS Mutual transfer

Source: Internet
Author: User

This code is directly available, you might as well try.
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<meta name= "keywords" content= ""/>
<meta name= "description" content= ""/>
&LT;TITLE&GT;HTML/JS Mutual Transfer Tool </title>
<script type= "Text/javascript" >
<!--
function Rechange () {
document.getElementById (' re '). Value=document.getelementbyid (' Oresult '). Value.replace (/document.writeln\ ("/g," " ). replace (/"\);/g," "). Replace (/\\\"/g, "\"). Replace (/\\\ '/g, "\"). Replace (/\\\//g, "\"). Replace (/\\\\/g, "\")
}
function Change () {
document.getElementById (' Oresult2 '). value= "Document.writeln (\" "+document.getelementbyid (' Osource '). Value.replace (/\\/g, "\\\\"). Replace (/\\/g, "\\/"). Replace (/\ '/g, ' \\\ ' "). Replace (/\"/g, "\\\"). Split (' \ r \ n '). Join ("\"); \ndocument.writeln (\ ") +" \ ");"
}
-
</script>
<style type= "Text/css" >
* {
Font-family:tahoma, Verdana;
font-size:12px;
padding:0;
margin:0;
}
Body {
Text-align:center;
Background: #D7E9FB;
}
#main {
margin:0 Auto;
padding:20px 50px;
width:600px;
Text-align:left;
Background: #FFF;
}
. box {
border:1px solid #D7E9FB;
margin:0 0 20px;
}
. box H2 {
Background: #D7E9FB;
Height:1.8em;
Line-height:1.8em;
Padding:0 10px;
}
. box. Con {
padding:20px 30px;
}
. Box TEXTAREA {
width:100%;
Overflow:hidden;
Background: #FFF;
border:5px solid #D7E9FB;
padding:2px;
}
H1 {
Text-align:center;
font-size:14px;
Line-height:2em;
Height:2em;
}
h3 {
margin:10px 0 0 0;
}
p {
margin:10px 0;
}
HR {
Border:none;
height:1px;
line-height:1px;
Background: #ccc;
}
#footer {
font-size:11px;
Text-align:center;
}
. button {
Font-weight:bold;
padding:5px 15px;
Border:none;
Background: #333;
Color: #FFF;
border-top:2px solid #999;
border-left:2px solid #999;
border-right:2px solid #000;
border-bottom:2px solid #000;
}
A
Color: #0CF;
}
</style>

<body>
<div id= "Main" >
<H1>HTML/JS Mutual Transfer Tool

<div class= "box" >
<div class= "Con" >
Please copy the <strong>Html</strong> source code to the following form: <br/>
<div><textarea id= "Osource" cols= "All" rows= "class=" "onfocus=" Change () "onkeyup=" Change () "></ Textarea></div>
<br/>
The following form is the corresponding <strong>JavaScript</strong> code: <BR/>
<textarea id= "Oresult2" cols= "rows=" "class=" ></textarea>
</div>
</div>

<div class= "box" >
<div class= "Con" >
Please copy the <strong>JS</strong> source code to the following form: <br/>
<div><textarea id= "Oresult" cols= "All" rows= "class=" "onfocus=" Rechange () "onkeyup=" Rechange () ">< /textarea></div>
<br/>
The following form is the corresponding <strong>Html</strong> code: <BR/>
<div><textarea id= "Re" cols= "rows=" "class=" ></textarea></div>
</div>
</div>

<div class= "box" >
<div class= "Con" >
Please copy the <strong>Html</strong> source code to the following form: <br/>
<div><textarea id= "isn" cols= "rows=" "class=" "></textarea></div>
<p align= "center" ><input type= "button" class= "button" value= "Past HTML Code Above, then click here" onclick= "smo Ke () "/></p>
</div>
</div>

<div id= "Footer" >
Copyright &copy; <a href= "http://www.21andy.com/" target= "_blank" >21Andy.com</a> all rights Reserved.
</div>


</div>

<script type= "Text/javascript" >
<!--
function $ () {
var elements = new Array ();
for (var i = 0; i < arguments.length; i++) {
var element = Arguments[i];
if (typeof element = = ' String ')
element = document.getElementById (element);
if (arguments.length = = 1)
return element;
Elements.push (Element);
}
return elements;
}


var spliff= "";
var medical= ' ";
var pot= "'";
var weed= "\ r";
var isn = document.getElementById (' isn ');

function Smoke () {
Spliff = Isn.value;
if (Spliff = = "") {
Alert ("Please enter the HTML code there is no code pasted the text window");
}
else {
Htmlpar ();
}
}

function Htmlpar () {
Isn.value= "Conversion in converting ...";
Pos=spliff.indexof (medical);
Pos1=spliff.indexof (pot);
if ((pos>-1) && (pos1>-1)) {
Rewrt ();
}
if (pos>-1) {
Qt=pot;
}
else{
qt=medical;
}
while (Spliff.indexof (weed) >-1) {
Lc=spliff.indexof (weed);
Spliff=spliff.substring (0,LC) + "" +spliff.substring (Lc+1,spliff.length);
}
nspliff= "<script type=" +qt+ "Text/javascript" +qt+ ">" +weed
+ "<!--" +weed
+ "document.write (" +qt+spliff.substring (0,36) +qt;
Spliff=spliff.substring (36,spliff.length);
Spliffl=spliff.length
pp=50;
if (PP&GT;SPLIFFL) {
PP=SPLIFFL;
}
while (spliffl>0) {
nspliff+= "\ r +" +qt+spliff.substring (0,pp) +qt;
Spliff=spliff.substring (PP,SPLIFFL);
Spliffl=spliff.length;
if (PP&GT;SPLIFFL) {
PP=SPLIFFL;
}
}
nspliff+= ");" +weed+ "//-" +weed+ "&LT;\/SC"
+ "ript>";
Isn.value=nspliff+weed+ "<!--Size:" +nspliff.length
+ "bytes-21andy.com--" +weed;
}
function Rewrt () {
Pos=-1;
while (Spliff.indexof (medical) >-1) {
Lc=spliff.indexof (medical);
Spliff=spliff.substring (0,LC) +pot+spliff.substring (lc+1,spliff.length);
}
}
function IA () {
This.length=ia.arguments.length;
for (Var i=0;i<this.length;i++) {
This[i]=ia.arguments[i];
}
}
-
</script>
</body>

HTML code escaping to JS, often encounter problems, this code to achieve HTML and JS Mutual transfer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.