首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

从iframe操作重定向父窗口

从问答内容中,我们可以知道您需要了解如何从iframe中操作重定向父窗口。以下是一个简单的示例,展示了如何在iframe中操作重定向父窗口:

代码语言:html
复制
<!DOCTYPE html>
<html>
<head>
 <title>Parent Window</title>
</head>
<body>
  <h1>Parent Window</h1>
 <iframe src="iframe.html" width="500" height="300"></iframe>
 <script>
    function redirectParent() {
      window.top.location.href = 'https://www.example.com';
    }
  </script>
</body>
</html>

在iframe.html文件中:

代码语言:html
复制
<!DOCTYPE html>
<html>
<head>
 <title>Iframe Window</title>
</head>
<body>
  <h1>Iframe Window</h1>
 <button onclick="redirectParent()">Redirect Parent</button>
 <script>
    function redirectParent() {
      window.parent.location.href = 'https://www.example.com';
    }
  </script>
</body>
</html>

在这个示例中,当用户点击iframe窗口中的按钮时,父窗口将被重定向到example.com。这个示例展示了如何使用JavaScript代码在iframe中操作重定向父窗口。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券