开发者

iFrame re-directs to an error page

开发者 https://www.devze.com 2023-02-10 00:46 出处:网络
I have a form that posts to an iFrame for processing. The iFrame then posts a form forwards in the parent window 开发者_Go百科to a confirmation.

I have a form that posts to an iFrame for processing. The iFrame then posts a form forwards in the parent window 开发者_Go百科to a confirmation.

I have added a session variable in the confirmation to indicate that the process is finished.

If the user clicks the back button the form in the iFrame redirects to an error page, but obviously that displays in the iFrame itself.

How can I make the error page trigger in the parent?

If Session("Complete") = 1 Then
     Response.Redirect("default.asp?Re-Entry")
End If


Instead of a Response.Redirect, you should use the following:

Response.Write( "<script language='Javascript'>" + _
                "window.parent.document.location.href = " + _
                "'default.asp?Re-Entry';" + _
                "</script>")

It will send back to the iFrame a portion of JavaScript that will instruct it's parent (the main page) to navigate to the error page.

Here is the complete code of my tests:

<%@ Language="VBScript" %>
<%
    If Request("op") = "process" Then
        If Session("Processed") = 1 Then
            Response.Write( "<script>" + _
                            "window.parent.document.location.href = " + _
                            "'error.asp?msg=AlreadyProcessed';" + _
                            "</script>")
        Else
            Session("Processed") = 1
            Response.Write( "<script>" + 
                            "alert('Hello, " + Request("name") + "!');" + _
                            "</script>")
        End If
        Response.End
    End If
%>
<html>
    <body>
        <iframe name="parallel" id="parallel" width="100%" height="50" />

        <form method="POST" target="parallel" action="iFrame.asp">
            <input type="hidden" name="op" value="process" />
            <b>Your Name</b><br/>
            <input type="text" name="name" width="250" /><br/>
            <button type="submit">Submit!</button>
        </form>
    </body>
</html>

I hope it helps.


i THINK the code u r using is wrong according to me if u use the below code that may help u

Response.Write("<scr" + "ipt language='Javascript'>" + _
               "document.parent.navigate('default.asp?Re-Entry');" + _
               "</scr" + "ipt>")
0

精彩评论

暂无评论...
验证码 换一张
取 消