被iframe页面更改顶层的跳转链接

界面被其他网页Iframe,需要修改顶层链接---方法如下

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <iframe src="./b.html" frameborder="0"></iframe>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button onclick="myButton()">跳轉頂級頁面</button>
  <script>
    function myButton() {
      console.log('aaa')
      window.top.location.href = 'http://10.10.10.11:6868/login.html'
    }
  </script>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/sugartang/p/13095597.html