JavaScript code execution box

Source: Internet
Author: User
  1. In the static demo library of a page component, I want to add a code runtime box to the page, find the concise and reliable code, and share it with the PHP programmer site.
  2. Reference content is as follows:
  3. Function runcode (OBJ ){
  4. VaR box = Document. getelementbyid (OBJ); // get the text box object
  5. VaR winname = Window. Open (''," _ blank ",''); // open a new window.
  6. Winname.doc ument. Open ('text/html ', 'replace'); // The New replace document overwrites the current document in the history list.
  7. Winname. Opener = NULL // prevents code from modifying the pop-up page
  8. Winname.doc ument. Write (box. Value); // write the value in the code box to this form
  9. Winname.doc ument. Close (); // close document operations
  10. }
  11. Call the runcode (OBJ) function and pass the ID attribute value of the text box. then, add an event handle to the button or hyperlink to activate the function, and you can run the code in the text box in the new window.
  12. Window. Open Method details:
  13. Syntax:
  14. Reference content is as follows:
  15. Onewdoc = Document. Open (Surl, sname)
  16. Parameters:
  17. Surl: required. String ). When a new document is opened, this parameter is used to specify the multi-purpose Internet Mail Extension protocol (mime-Multipurpose Internet Mail Extensions) for the document ). The default value is text/html. Currently, this method only supports this mime type.
  18. Sname: Optional. String ). If this parameter is set to replace when a new document is opened, the new document overwrites the current document in the history list. If this parameter is ignored, the new document is simply added to the end of the History list. Replace: the new document overwrites the current document in the history list.
  19. Return Value:
  20. Onewdoc: Object (element ). Returns a reference to the new document object.
  21. Note:
  22. Open the new document to prepare the write and writeln output.
  23. When an event-triggered function on an object in the document calls the open method, the open method of the window object is used. When the open method is directly used for events on objects in the document, the open method of the document object is used.

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.