Zwróć treść HTML jako łańcuch, podany adres URL. Funkcja Javascript

Chcę napisać funkcję javascript, która zwraca treść HTML jako ciąg znaków podany adres URL funkcji. Znalazłem podobną odpowiedź na Stackoverflow.

Próbuję użyćta odpowiedź rozwiązać mój problem.

Jednak wydaje się, że takdocument.write() nic nie pisze. Po załadowaniu strony otrzymuję pusty ekran.

<html>
<head>
</head>
<body>  
  <script type="text/JavaScript">
  function httpGet(theUrl)
  {
    var xmlHttp = null;

    xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false );
    xmlHttp.send( null );
    return xmlHttp.responseText;
  }
  document.write(httpGet("https://stackoverflow.com/"));
  </script>
</body>
</html>

questionAnswers(3)

yourAnswerToTheQuestion