웹 페이지에서 HTML 실행 - 구현 코드

25254 단어
실현 방식은 결코 이런 것이 아니다. 다음 코드는 참고만 제공한다.
DOCTYPE html>
<html>
<head>
<meta content="'text/html;" charset="utf-8" http-equiv="Content-Type" />
<title>    title>
<script>
//    
function doRun(param)  {
    
     cod=document.getElementById(param)
      var code=cod.value;
      if (code!=""){
          var newwin=window.open('','','');  
          newwin.opener = null 
          newwin.document.write(code);  
          newwin.document.close();
    }
}
//
function doCopy(param) { 
    if (document.all){
         textRange = document.getElementById(param).createTextRange(); 
         textRange.execCommand("Copy"); 
    }
    else{
         //alert("      IE   ");
         copyToClipboard(document.getElementById(param).value);
    }
}
//     
function saveCode(param) {
    cod=document.getElementById(param)
    var code=cod.value;
    if (code!=""){
        var winname = window.open('', '_blank', 'top=10000');
        winname.document.open('text/html', 'replace');
        winname.document.write(code);
        winname.document.execCommand('saveas','','code.htm');
        winname.close();
    }
}
function copyToClipboard(txt) {
     if(window.clipboardData) {
             window.clipboardData.clearData();
             window.clipboardData.setData("Text", txt);
     } else if(navigator.userAgent.indexOf("Opera") != -1) {
          window.location = txt;
     } else if (window.netscape) {
          try {
               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
          } catch (e) {
               alert("
'about:config'
'signed.applets.codebase_principal_support' 'true'
"); } var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard); if (!clip) return; var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable); if (!trans) return; trans.addDataFlavor('text/unicode'); var str = new Object(); var len = new Object(); var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); var copytext = txt; str.data = copytext; trans.setTransferData("text/unicode",str,copytext.length*2); var clipid = Components.interfaces.nsIClipboard; if (!clip) return false; clip.setData(trans,null,clipid.kGlobalClipboard); } } script> <style> .btn { background-color: #A5A5A5; /* Green */ //border: none; color: white; padding: 5px 10px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; } .textarea { background-color: #CCE8CF; padding: 5px 10px; text-decoration: none; display: inline-block; font-size: 16px; } style> <script> /* // window.open ;  // 'page.html' ;  // 'newwindow' ( ), , '' ;  // height=100 ;  // width=400 ;  // top=0 ;  // left=0 ;  // toolbar=no ,yes ;  // menubar,scrollbars 。  // resizable=no ,yes ;  // location=no ,yes ;  // status=no ( ),yes ; function doRun() { var winEx2 =window.open('', 'newwindow', 'height=300, width=400, top=200px, left=300px, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no'); //window.open("", "winEx2", "width=500,height=300,status=yes,menubar=no,scrollbars=yes,resizable=yes"); //window.open('', 'newwindow', 'height=300, width=400, top=200px, left=300px, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no'); winEx2.document.open('text/html', 'replace'); winEx2.document .write(unescape(event.srcElement.parentElement.children[0].value)); winEx2.document.close(); } function saveFile() { var win = window.open('', '', 'top=10000,left=10000'); win.document.write(document.all.t1.innerText) win.document.execCommand('SaveAs', '', 'a.html') win.close(); } */ script> head> <body > <div align="center" class="UBBContent"> <textarea id="t1" name="textfield" class="textarea" rows="30" cols="100"> <!Doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title> </title> </head> <body> <script src="http://code.jquery.com/jquery-1.4.1.js"></script> <script type="text/javascript"> // window.onload = function() { //(document) document.getElementById('note').onkeyup = function() { document.getElementById('text-count').innerHTML=this.value.length; } //(jquery) $('#note2').keyup(function() { // var val=$('#note2').val(); // var len=val.length; var len=this.value.length $('#text-count2').text(len); }) } </script> <div> <textarea cols="40" rows="5" id="note" name="note" maxlength="100" value="" οnkeyup="this.value=this.value.substring(0, 100)" placeholder=" 100 "></textarea><span id="text-count" value="">0</span>/100 </div> <div> <textarea cols="40" rows="5" id="note2" name="note2" maxlength="100" value="" οnkeyup="this.value=this.value.substring(0, 100)" placeholder=" 100 "></textarea><span id="text-count2" value="">0</span>/100 </div> </body> </html> textarea><br><br> <input name="Button" class="btn" onclick="doRun('t1')" type="button" value=" " /> <input name="Button" class="btn" onclick="t1.select('t1')" type="button" value=" " /> <input name="Button" class="btn" onclick="t1.value=''" type="button" value=" " /> <input onclick="saveCode('t1');" class="btn" type="button" value=" " /><br> <span>[Ctrl+A : , ]span><br> div> body> html>

구체적인 효과는 전편을 보십시오!!!
전재 대상:https://www.cnblogs.com/libf/p/7490014.html

좋은 웹페이지 즐겨찾기