The ability to access multiple websites, in a browser, via javascript is heavily limited for security reasons. I'm going to call this idea of displaying other webpages via javascript an iframe imitator. For this application, I would set three categories of sites:
- Host Site: on the host site, an iframe imitator can be made with a simple ajax request. This is kid's stuff.
- 1st Party Site (Other than Host): On any site where you have access to server configurations (or at least can modify headers), you will need to specify the header
Access-Control-Allow-Origin: "host site name here"
to allow the host site's access or Access-Control-Allow-Origin: *
to allow every site's access.
- 3rd Party Site: On third party site's you will have to hope that the site's
Access-Control-Allow-Origin
header is set to *
or else you will need to convince the site's administrators to make an exception and allow your site's access.
If none of the above conditions can be met, then you will be at the mercy of the user's browser security. Some browsers support CORS (Cross Origin Resource Sharing), but it is not dependable. Typically, a user's browser blocks access to certain headers (for security reasons), but if the browser provides support (or has loose enough security), then the headers can be set to trick other sites into giving you access. Be aware that (if allowed) some might consider this borderline hacking, and it probably shouldn't be used without the permission of all parties involved.
$(document).ready(function() {
var target_domain = "www.web-source.net";
var protocol = "http://";
var path = ""; //e.g. "/index.html"
var target_host = protocol + target_domain;
var target_URI = target_host + path;
var method = "GET";
$.ajax({
url: target_URI,
type: method,
headers: {
"X-Requested-With": "", //nullifies the default AJAX value of "XMLHttpRequest"
"Origin": target_host, //lies to the target server
"Referer": target_host, //lies to the target server
"X-Http-Method-Override": method, //forces the specified method
},
crossDomain: "true" //applies cross domain settings
});
});
$(document).ajaxSuccess(function() {
$("#iframe_imitator").html(xhr.responseText);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="iframe_imitator"></div>