2

This code is working in Dreamweaver default browser but not in chrome or firefox. It shows only blank page , without showing google.com. Don't know why! May be the problem is with iFrame. But I have to show something other page in my page. Is there any workaround??

<!DOCTYPE html>

<html>
<head>
<title>booo yeah</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js" ></script>
<script type="text/javascript">
    $(document).ready(function() {
        var height = $(window).height();
        var width = $(window).width();
        $('iframe').width(width);
        $('iframe').height(height);
}); 
</script>
</head>
<body>
<iframe src="http://www.google.com" frameBorder="0"></iframe>
</body>
</html>

Screenshot:http://goo.gl/jTpB2g On back there is dreamweaver with left side code and right side its default browser showing the working code. In front, there is chrome in which nothing is showing

4 Answers4

3

The website you are trying to display has security that prevents it from being used in iframe. for example <iframe src="http://www.w3schools.com"></iframe> works fine. The problem is not with your browser.

Simo Mafuxwana
  • 3,702
  • 6
  • 41
  • 59
0

It's probably not displaying for security reasons.

Same Origin Policy

The same origin policy prevents a document or script loaded from one origin from getting or setting properties of a document from another origin. This policy dates all the way back to Netscape Navigator 2.0.

Some websites do allow it but Google doesn't. Strange that it's ok with Dreamweaver doing it.

There are ways you can circumvent it (I can't say they'll be suitable for your problem though).

Ways to circumvent the same-origin policy

Community
  • 1
  • 1
ajtrichards
  • 29,723
  • 13
  • 94
  • 101
0

As ajtrichards said, Google has restrictions due to Same Origin Policy.

Just try another domain you will see that your code works

jsbin.com/UJeHaqe/1/edit

Hasan Alaca
  • 232
  • 2
  • 14
0

Open you console panel and you can see an error message says:

Refused to display 'https://www.google.com/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

Google search returns an X-Frame-Options header with SAMEORIGIN, that meas this page can only be displayed in a frame on the same origin as the page itself.

See more from X-Frame-Options

Solutions:

If you have access to the site, try set X-Frame-Options to ALLOWALL or simply remove this from http response.

If you are stuck at google, try use Google Custom Search instead, replace your url with this http://www.google.com/custom, which sends 'X-Frame-Options: ALLOWALL ' which allows you to embed this site in your IFRAME.

lastr2d2
  • 3,604
  • 2
  • 22
  • 37