Node.js http.get
17,205
Solution 1
Simplest solution is to add <base href="http://google.com/"> to the html. Preferably in the head, so do string replace on '<head>' and replace in with '<head><base href="http://google.com/">'
Solution 2
Wouldn't it be easier to have the client fetch the Google page?
<html>
<head>
<script>
window.onload = function () {
var nif = document.createElement("iframe");
nif.width = 850;
nif.height = 500;
nif.src = "http://www.google.de";
nif.appendChild( document.createTextNode("no iframe support") );
document.body.appendChild(nif);
};
</script>
</head>
<body>
<h1>IFRAME</h1>
</body>
</html>
Related videos on Youtube
Comments
-
Hacknightly almost 2 years
I have the following code that requests the Google.com homepage and sends the page data back to an Iframe on the client side.
var options = { host: 'www.google.com', port: 80, path: '/', method: 'GET' }; var req = http.get(options, function(res) { var pageData = ""; res.setEncoding('utf8'); res.on('data', function (chunk) { pageData += chunk; }); res.on('end', function(){ response.send(pageData) }); });
However, all images and CSS are broken in the iframe? How can I preserve the images and CSS?
-
Gerben over 12 yearsPS. you probably also have to strip the JS, because AJAX won't work cross origin.
-
Hacknightly over 12 yearsHm, I've never seen that before.... Sounds reasonable, I'm going to give it a shot, thank you ; )
-
Hacknightly over 12 yearsDude, you saved me another week of wanting to bang my head against my monitor. Thank you, a thousand times thank you.
-
Hacknightly over 12 yearsAhh, sorry, I failed to mention that I'm on the server side making the request via Node js.
-
Gerben over 12 yearsYou're a thousand times welcome. I think your monitor will be pleased :-)
-
Lumi over 12 yearsSure, I noticed; I just didn't understand why when it is easier on the client side. Well, there may be a reason ... just couldn't figure out what it could be.
-
Hacknightly over 12 yearsActually, I now see how your solution is viable. I'm going to give this a shot also.
-
Lumi over 12 yearsGood. :) And of course you can hardcode the IFRAME, making it even easier - if that's allowed by the problem's constraints.