0

I was designing a webcode editor from textarea tag

Index.html

<textarea id="code"></textarea>

I want to get full code of other page in textarea but how to do it

other.html

<!Doctype html>
 <html>
   <head>
     <title>title</title>
   </head>
   <body>
     //something code...
   </body>
</html>
  • Does this answer your question? [get html code using javascript with a url](https://stackoverflow.com/questions/6375461/get-html-code-using-javascript-with-a-url) – Claudio Busatto May 10 '20 at 11:40
  • Hi Rajmani, welcome to Stack Overflow! Have a look in [this question](https://stackoverflow.com/questions/6375461/get-html-code-using-javascript-with-a-url), it has different strategies to solve a very similar issue – Claudio Busatto May 10 '20 at 11:42

2 Answers2

0

You can use file_get_contents().

<?php
$code = file_get_contents('other.html');
?>

<textarea id="code"><?=$code?></textarea>

More information here: https://www.php.net/manual/en/function.file-get-contents.php

fraggley
  • 1,215
  • 2
  • 9
  • 19
0

Please try the following answer, running script in Javascript

function readSingleFile(evt) {
  //Retrieve the first (and only!) File from the FileList object
  var f = evt.target.files[0]; 

  if (f) {
    var r = new FileReader();
    r.onload = function(e) { 
      var contents = e.target.result;
     document.getElementById('txtArea').value = contents;
    }
    r.readAsText(f);
  } else { 
    alert("Failed to load file");
  }
}

document.getElementById('htmlFile').addEventListener('change', readSingleFile, false);
<form action="">
  <input type="file" name="pic" accept="html" id="htmlFile">
</form>

<textarea id="txtArea"></textarea>
Dupinder Singh
  • 7,175
  • 6
  • 37
  • 61