PHP “header (location)” inside IFRAME, to load in _top location?

前端 未结 8 1787
名媛妹妹
名媛妹妹 2020-12-03 10:20

I have a simple form which is inside IFRAME. When user click on SUBMIT, it redirects to a specific page on my server. The function I use for the redirect is



        
相关标签:
8条回答
  • 2020-12-03 10:52

    You can use javascript to access the parent. You could echo out javascript in your PHP.. so your parent page has this:

    function changeURL( url ) {
        document.location = url;
    }
    

    and in your php script, you echo

    <script>
       parent.changeURL('mypage2.html' );
    </script>
    

    The reason you can't call parent.document.location is because it's read only - you have to have a function available on the parent to do it.

    0 讨论(0)
  • 2020-12-03 10:58

    The best and simplest thing to do is to use the form target element

    <form action="..." target="_top"> 
    <form action="..." target="_parent">
    

    either of the target parameters works fine

    0 讨论(0)
提交回复
热议问题