Why does the webpage go to a whitepage when I change the iframe code?

Joined
Jun 30, 2014
Messages
147
Reaction score
36
Ive tried as couple of iframe codes now which work fine when i open them with their default url.

But as soon as i try changing the url to a different one than the original i jsut get a blank white screen.

Can anyone explain why?

Code:
<html>
<head>
    <title>title</title>
    <meta name="keywords" content="keyword 1, keyword 2" />
    <meta name="description" content="Enter your page description" />
    <style>
    * {
        margin: 0;
        padding: 0;
    }
    body {
        margin: 0;
        padding: 0;
    }
    </style>
</head>

<body>
<iframe src="google url (cant add links myself)"></iframe>
</body>
</html>

The original here was peerfly homepage but as soon as I change it to google to test i get whitepage.

Explanation please?
 
The site sends an http header that tells the browser "don't you dare put me inside a frame or I 'll put a horse-head on your bed while you sleep". Your browser complies.
 
So no way around that then? if it doesnt work it means the website forbids it? I noticed that i could do it with the root domain but not with the link with my affiliate link on, does that mean its forbidden or not since it worked on the homepage?
 
No way around it - the site can choose which pages to allow to be framed as it can send a different X-header per page.
 
There's a way around it, but you need your own PHP script to act as a proxy.

Example:

Your html
======

Code:
<html><head>
    <title>title</title>
    <meta name="keywords" content="keyword 1, keyword 2" />
    <meta name="description" content="Enter your page description" />
    <style>
    * {
        margin: 0;
        padding: 0;
    }
    body {
        margin: 0;
        padding: 0;
    }
    </style>
</head>


<body>
<iframe src="{url to your php script}"></iframe>
</body>
</html>

Your PHP script
=========

Code:
<?php
$url = '//youraffillink/';

$data= file_get_contents($url);

// you can modify $data in the way you want, if needed

echo $data;
?>
 
There's a way around it, but you need your own PHP script to act as a proxy.

It 's not the same, as it is not the visitor that will visiting the "framed" page, but the server. This means he won't be logged it, count as unique ip etc. etc.

Normally

Visitor -> Page A -> Frame Page (gets cookies)

Proxied

Visitor -> Page A -> Server -> Page A with B's content (no cookies sent to B server)
 
Good point, but even in the "normal" example you've provided I think (I'm not really sure and I don't have much time to create a test case now) a visitor can't access the framed page cookies and vice versa because of the cross-domain-origin restriction.

But if that's not the case, you can still change the script a little to load the affiliate page via curl() (instead of file_get_contents) then forward a cookie retrieved via curl() to a visitor (via set_cookie) and it should work the way you want.
 
do you really need to iframe a site that doesn't allow that or was it just for testing purposes. As it was explained each site can choose not to let people iframe their content, if you put a lot of work into it maybe you'll manage to do it though do you really need that or you were just wondering if your code is wrong (which is not, you just picked a bad testing site- google ) :)
 
Good point, but even in the "normal" example you've provided I think (I'm not really sure and I don't have much time to create a test case now) a visitor can't access the framed page cookies and vice versa because of the cross-domain-origin restriction.

Sorry, it was ambiguous the way I wrote it. I meant that the visitors's browser sends the cookies to the framed page's server when using an iframe.

So, if you make a test page that has an iframe set to bhw, when you visit the test page bhw will get your bhw cookies. With proxy instead of iframe, bhw will not get your cookies (won't be logged in).
 
Back
Top