单击<a>链接时不会发生页面重定向.X帧选项设置为“DENY”


page redirect not happening on click of <a> link. X-Frame-Options set to 'DENY'

在我网站上的特定页面上说 example.com/redirect.php 我已经编写了一个锚标签<a href="http://news.ycombinator.com/item?id=5311151">path</a>

单击此链接时,页面未加载。在检查元素时,我收到此错误:

拒绝在帧中显示"https://news.ycombinator.com/item?id=5311151",因为它将"X帧选项"设置为
"DENY">


谷歌搜索后,我发现这是预期的行为,因为其他网站的所有者不想在其域之外的iframe中显示其内容。

我已经尝试过这些,但它们都在 iframe 中加载。

  1. window.location.href = "https://news.ycombinator.com/item?id=5311151";
  2. <?php header(location: https://news.ycombinator.com/item?id=5311151"); ?>
  3. window.location.replace("https://news.ycombinator.com/item?id=5311151"(;


我有两个问题:

  1. 为什么在单击路径链接时,新页面在同一页面上的iframe中加载(重定向.php(,而不是重定向到ycombinator的页面。
  2. 如何让用户重定向到我网站之外的任何页面。

附言我正在使用灯组。

更新:正如Serge Seredenko在评论中建议的那样,我尝试使用top.location.href = "...";这对我有用,我能够重定向页面。

另一个问题:我需要推荐人的网址。使用 Serge Seredenko 的方法执行重定向后,我没有获得 $_SESSION['HTTP_REFERER'] 的实际引用网址,而是获得内部网址。我需要实际的引用网址。

我尝试使用以下方法进行服务器端 url 重定向:
<?php header(location: https://news.ycombinator.com/item?id=5311151"); ?> .
但是我收到此错误:">X帧选项"到"同源"。

如何使服务器端网址重定向并保留实际的引用网址?
提前非常感谢:)

1(请记住,在发送任何实际输出之前,必须调用 header((,无论是通过普通的 HTML 标记、文件中的空行还是从 PHP 发送。读取包含或require函数或其他文件访问函数的代码,并且在调用header((之前输出空格或空行,这是一个非常常见的错误。使用单个 PHP/HTML 文件时也存在同样的问题。http://php.net/manual/en/function.header.php

2(试试这个:

<?php
//...some your code
print '<script type="text/javascript"> location.replace("https://google.com/"); </script>';
//...
?>

通常,当您收到此X-Frame-Options错误时,浏览器期望收到"部分"HTML页面。不是带有标签等的完整 HTML 页面。

这意味着当浏览器向服务器发出请求时。例如,如果两个屏幕都处于"过渡模式"(Source and destination for example in same page but in different tab like this situation).我们得到同样的错误。