You only need an HTML page to view the Javascript execution result you have compiled!

Source: Internet
Author: User

When I work and study, I often encounter the need to view the execution results of the JavaScript code compiled by myself. It's okay in Firefox, but there is firebug, but IE6 won't work well, so, it makes a simple page to view the execution result of JavaScript code. js code can contain single lines (// comment content) and multiple lines of comments (/* Comment content */) (The content is super Elementary, free to play, please fly ).

 

The complete HTML page code is as follows:

<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> JavaScript test tool! </Title>
<Meta name = "author" content = "yakoo5@163.com">
<Meta name = "Description" content = "a webpage that can directly execute JavaScript">
</Head>
<Body>
<Br/>
<Br/>
<H2>
<Font color = "blue"> A webpage that can directly execute JavaScript! </Font>
</H2>
Author: <a href = "mailto: yakoo5@163.com"> yakoo5@163.com </a> <br/>
Date: 2010-11-26 <br/>
Version: 1.1

<HR/>
<SCRIPT type = "text/JavaScript" Language = "JavaScript">
Function executejs (){
VaR Codes = Document. getelementbyid ('Codes '). value;

If (''= codes ){
Alert ('Enter the code! ');
Return;
}

VaR codearray = codes. Split ('\ n ');

VaR purecode = ''; // stores pure JavaScript code that removes" // "single-line comments
For (VAR I = 0; I <codearray. length; I ++ ){
VaR code = codearray [I];
If (code. indexof ('//')>-1 ){
Code = code. substr (0, code. indexof ('//'));
} Else if (''! = Code &&! /^ \ S * $/. Test (CODE )){
Code = trim (CODE );
}
Purecode + = code + '\ n ';
}

Try {
Eval (purecode );
} Catch (exception ){
Alert (exception );
}
}

// Remove spaces at both ends of the string
Function trim (STR ){
If (null! = Str) return Str. Replace (/^ \ s +/, ''). Replace (/(\ s +) $ /,'');
Else return STR;
}
</SCRIPT>
<Br/>

Enter the JavaScript code in the text box below and click & nbsp;

<Input type = "button" value = "running" onclick = "executejs ()">

& Nbsp; view the result.
<Br/>
<Textarea id = "codes" rows = "15" Cols = "100"> alert ('Hello! '); </Textarea>
</Body>

</Html>

You can copy the above Code and save it as an HTML page to view the effect.

Related Article

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.