Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
43
rated 0 times [  49] [ 6]  / answers: 1 / hits: 17306  / 13 Years ago, mon, august 22, 2011, 12:00:00

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?


More From » node.js

 Answers
121

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/>'


[#90488] Saturday, August 20, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryderalfonsos

Total Points: 655
Total Questions: 88
Total Answers: 91

Location: Nauru
Member since Thu, Feb 2, 2023
1 Year ago
ryderalfonsos questions
Mon, Sep 9, 19, 00:00, 5 Years ago
Wed, Feb 13, 19, 00:00, 5 Years ago
Tue, Feb 12, 19, 00:00, 5 Years ago
Fri, Dec 28, 18, 00:00, 6 Years ago
;