首页 > 解决方案 > iframe 内的内容重定向但不是整个页面

问题描述

所以我有一列里面有这个代码:

<div class="cat">
  <iframe src="sidebar.html" frameborder="0" ></iframe>
</div>

这是“sidebar.html”内的一行:

<th target="_top" onclick="window.location='http://example.com'">example</th>

(请记住,这是表格的一部分)

当我点击“示例”这个词时,它实际上会重定向到它应该的位置,但这仅在 iframe 内可见

我想将整个页面重定向到 www.example.com

标签: htmlcss

解决方案


只需添加“父母”。在 window.location 之前:

<th target="_top" onclick="parent.window.location='http://example.com'">example</th>

推荐阅读