search

Home  >  Q&A  >  body text

javascript - The page in the iframe frame controls the parent frame page to jump to a certain address

As shown in the picture, how to use js on page B to control page A to jump to a certain address?

淡淡烟草味淡淡烟草味2719 days ago927

reply all(3)I'll reply

  • 仅有的幸福

    仅有的幸福2017-06-23 09:13:55

    If it is from the same source, just window.parent.location.href can be used directly.
    There is no solution if there are different sources and no control over the A page.

    reply
    0
  • 三叔

    三叔2017-06-23 09:13:55

    In the js of the B pagewindow.parent.window.location.href = '//www.baidu.com'

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-06-23 09:13:55

    a.html

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <meta charset="utf-8">
    </head>
    <body>
        <iframe src="b.html"></iframe>
    </body>
    </html>

    b.html

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <meta charset="utf-8">
        <script type="text/javascript">
        function parentJump() {
            window.parent.location.href = 'http://www.baidu.com/';
        }
        </script>
    </head>
    <body>
        <button onclick="parentJump();">父页面跳到百度</button>
    </body>
    </html>

    Use window.parent to access the parent form from a page in an iframe.

    reply
    0
  • Cancelreply