Javascript iFrame重新定向到错误页面

Javascript iFrame重新定向到错误页面,javascript,html,iframe,asp-classic,Javascript,Html,Iframe,Asp Classic,我有一个表单可以发布到iFrame进行处理。iFrame然后在父窗口中将表单转发到确认 我在确认中添加了一个会话变量,以指示流程已完成 如果用户单击“上一步”按钮,iFrame中的表单将重定向到错误页面,但显然,该页面会显示在iFrame本身中 如何在父级中创建错误页触发器 If Session("Complete") = 1 Then Response.Redirect("default.asp?Re-Entry") End If 您应该使用以下命令,而不是Response.Red

我有一个表单可以发布到
iFrame
进行处理。iFrame然后在父窗口中将表单转发到确认

我在确认中添加了一个会话变量,以指示流程已完成

如果用户单击“上一步”按钮,iFrame中的表单将重定向到错误页面,但显然,该页面会显示在iFrame本身中

如何在父级中创建错误页触发器

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

您应该使用以下命令,而不是Response.Redirect:

Response.Write( "<script language='Javascript'>" + _
                "window.parent.document.location.href = " + _
                "'default.asp?Re-Entry';" + _
                "</script>")
Response.Write(“”+_
“window.parent.document.location.href=“+_
“'default.asp?重新输入';”+_
"")
它将向iFrame发回一部分JavaScript,该部分JavaScript将指示其父级(主页)导航到错误页面

以下是我测试的完整代码:

<%@ 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>

您的名字

提交

我希望它能帮助你。

我认为,如果你使用下面的代码可能会对你有所帮助,那么我认为你使用的代码是错误的

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

页面抛出了任何JS错误,或者根本没有做什么?您正在使用哪个浏览器?它将继续重新发布表单,而不是重定向。使用ChromeWhy response.write所有脚本?为什么不干脆
%>parent.location='default.asp?重新输入'只是风格问题。效果几乎相同,可读性更强。事实上,“所有脚本”都包含在您的版本中。使用“window.parent.document.location”代替缩写形式只是为了清除DOM路径。这里的想法只是为了说教。有上千种其他方法可以做同样的事情。我不是在建议使用XHR而不是Darren的方法,我指的是所有的引号和+和u,而不是asp代码之外的脚本块。我个人认为这更具可读性。此外,我怀疑您是否需要像编写文档时那样转义脚本标记。编写themdocument.navigate不太兼容。改用parent.location=“…”代替