Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Let's say my homepage is www.example.com and I want to add a div on it. When people visit my page, I want to show the content from www.google.com within the div.

When visitor clicked any link on www.google.com, it redirects user all within the div. Is it possible to do? If so, how?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

No, the element you are looking for is an iframe, which does about exactly what you ask.
There's a mayor downsite to this: This is bad for seo, you don't get points for the content in the iframe.
Also, you can't Iframe Google, they don't allow you to. Other sites will work.


The default styling of an iframe is a bit (well, a lot) ugly, so with some basic styling it will look more like the "div-look":

iframe{
    margin: 0;
    padding: 0;
    border: 1px solid #000; /* Can be [none] too */
    display: block;
}
share|improve this answer

Or you could grab the contents of the other page/site and load it into the div.

  1. Dynamic creation (serverside language)
  2. Ajax creation (using javascript and a your serverside language)

You can now use something like PHP's file_get_contents("the-web-page-url") to load the content into a div

share|improve this answer
1  
serverside will not work, the links found will link to the original page. You could counter this by prefixing all anchors with 'openViaMySite.php?url=example.com`, but that is a disaster waiting to happen (think of the exploit possibilities!) –  Martijn Jun 17 at 13:40
    
So grab it into a variable and run a preg_match_all on it. Convert all absolute to relative or remove anchors entirely –  f00644 Jun 17 at 13:42
    
Please promise me you dont do that. stackoverflow.com/questions/1732348/… –  Martijn Jun 17 at 14:04
1  
Yes and a dangerous one, of which the downsides should be mentioned, so any that anyone who might consider this base their solution on the complete picture. –  Martijn Jun 17 at 14:11
1  
We should also mention that using another website's content is a dangerous one ;) –  f00644 Jun 17 at 14:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.