I want to write a javascript function that returns HTML content as string given URL to the function. I found a similar answer on Stackoverflow.
I am trying to use this answer to solve my problem.
However, it seems as though document.write()
isn't writing anything. When I load the page, I get a a blank screen.
<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>
The only one i have found for Cross-site, is this function:
you need to return when the readystate==4 e.g.
after you get the response just do call this function to append data to your body element
@satya code modified as below