To do that you can try to use XMLHttpRequest to make a request to the url you want then, handle the response with the status code of your needs.
var req = new XMLHttpRequest();
req.open('GET', 'http://www.mozilla.org/', true);
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4) {
if(req.status == 200)
dump(req.responseText);
else
dump("Error loading page\n");
}
};
req.send(null);
Source using xmlhttp request
As you posted a comment above, I will teach you how you can navigate through a website gathering all external or internal links parsing the html.
Get the link somehow then send to getHtml() function, I suggest you to try this
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="main.js"></script>
<style>
p{
margin: 0px;
margin-block-end: 0px;
margin-bottom: 0px;
}
</style>
</head>
<body>
<input type="text" id="link">Ingrese enlace
<button onclick="getHtml(document.getElementById('link').value)">Get External Content</button>
<div id="div1"></div>
</body>
</html>
main.js
function getHref(links, as){
var as_length = as.length;
var links_length = links.length;
for (let index = 0; index < as_length; index++) {
var element = as[index].href;
$("#div1").html($("#div1").html()+`<br>> ${element}`);
if(element.indexOf(window.location.href)>-1){
$("#div1").html($("#div1").html()+` - <p style='color:purple;'> current path DETECTED action: discarting... </p>`);
element="0";
}
if(element.indexOf("file:///C:/") > -1) {
element = element.replace("file:///C:/", initiator);
$("#div1").html($("#div1").html()+` - ${element}`);
}
else if(element.indexOf(initiator)> -1){
$("#div1").html($("#div1").html()+` - ${element}`);
}
else if(element.indexOf("file://") > -1) {
element = element.replace("file://", initiator);
$("#div1").html($("#div1").html()+` - <p style='color:red;'> External domain DETECTED action: discarting...</p>`);
}
else if(element.indexOf("mailto:") > -1) {
element =0;
$("#div1").html($("#div1").html()+` - <p style='color:cyan;'> External action DETECTED action: discarting... </p>`);
}
else if(element.indexOf("tel:") > -1) {
element=0;
$("#div1").html($("#div1").html()+` - <p style='color:cyan;'> External action DETECTED action: discarting...</p>`);
}
getHtmlChild(element);
}
}
function parseHtml(htmls)
{ // console.log(html);
$("#div1").html($("#div1").html()+"<br>>Parsing...");
var ele = document.createElement('div');
ele.innerHTML = htmls;
console.log(ele);
var link_tag = ele.getElementsByTagName('link');
var a_tag = ele.getElementsByTagName('a');
$("#div1").html($("#div1").html()+`<br>>found ${link_tag.length} <b><u>link</u></b> tags and ${a_tag.length} <b><u>a</u></b> tags., BAD TAGS ARE ELIMINATED! `);
getHref(link_tag, a_tag);
//console.log(link_tag[0].href);
}
function getHtml(urls){
console.log("INICIADOR:" + urls);
if(urls[urls.length-1]!="/"){
urls = urls+"/";
}
initiator=urls;
proceses++;
$.ajax({
url: `${urls}`,
method: "GET",
crossDomain: true,
success: function(data) {
$("#div1").html(">Content is succefull gathered....");
parseHtml(data);
}
});
}
It will display all the links :)