【问题标题】:Serverside redirect from iframe not working in Firefox and Chrome but works in IE6来自 iframe 的服务器端重定向在 Firefox 和 Chrome 中不起作用,但在 IE 6 中起作用
【发布时间】:2013-05-21 11:42:49
【问题描述】:

我很想知道为什么以下内容在 Firefox 21 和 Chrome 26 中不起作用,但在 IE 6 中起作用。

我有一个包含 iframe 的页面“frame.html”。

iframe 指向另一个页面“post.html”。

post.html 包含一个将用户名 POST 到服务器 php 页面“redirect.php”的表单。

服务器以重定向到谷歌的方式响应。

在 IE6 中,Google 页面出现在 iframe 中,但在 Firefox 和 Chrome 中却没有。

有谁知道为什么会发生这种情况,以及在现代浏览器中是否有可能?

谢谢。

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; ?>

【问题讨论】:

    标签: php html http redirect iframe


    【解决方案1】:

    现代浏览器内置了跨域保护。

    例如。 Google Chrome 将此消息记录到控制台:

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

    如果您要使用您域中的页面,它会起作用。

    【讨论】:

    • +1。值得一提的是,这在 IE6 中有效,因为 IE6 没有现代安全功能,因此它的用户很容易被黑客入侵。这就是为什么您应该停止使用它(并停止在您的网站中支持它)。
    • 我正在使用本地主机中的所有文件...仍然重定向在 IE 中不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    • 2011-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-03
    • 2014-08-31
    相关资源
    最近更新 更多