user1810292
user1810292

Reputation: 279

Serverside redirect from iframe not working in Firefox and Chrome but works in IE6

I would love to know why the following does not work in Firefox 21 and Chrome 26 yet it works in IE 6.

I have a page "frame.html" which contains an iframe.

The iframe points to another page "post.html".

post.html contains a form which POSTs a username to a server php page "redirect.php".

The server responds with a redirect to google.

In IE6 the Google page appears in the iframe, but in Firefox and Chrome it doesn't.

Does anyone know why this happens and if it's even possible in a modern browser?

Thanks.

frame.html

<html>
<head>
<title>Frame</title>
</head>
<body>
<iframe width="800" height="800" src="post.html"/></iframe>
</body>
</html>

post.html

<html>
<head>
<title>Post</title>
</head>
<body>
<form action="http://myserver.com/redirect.php" method="post">
<input type="text" name="username"/>
<input type="submit" value="Send"/>
</form>
</body>
</html>

redirect.php

<?php header('Location: http://www.google.com'); exit; ?>

Upvotes: 0

Views: 1632

Answers (1)

Bart
Bart

Reputation: 17361

Modern browsers have cross domain protection builtin.

For instance. Google Chrome logs this message to the console:

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

If you would use a page that is on your domain it will work.

Upvotes: 1

Related Questions