【问题标题】:Redirect iframe after form submit表单提交后重定向 iframe
【发布时间】:2013-08-06 00:51:44
【问题描述】:

我创建了一个包含 iframe 的 asp 页面。 iframe 包含一个表单,在表单提交时我想将 iframe 重定向到另一个页面。

这个方法我试过了:

//iframe content:
 <html>
  <head>
    <script type="text/javascript"> 
       function onformsubmit()
       {
        setTimeout(function ()
        {
            $(top.document).find('#page').attr('src', 'page2.aspx');
        },1000);
       }
   </script>     
 </head>
 <body>
     <form id="form1" runat="server" onsubmit="onformsubmit()">
      ...
      <div class="menubar">
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"  CommandName="Update" Text="Update" />
            &nbsp;
            <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </div>
       ...
     </form>
  </body>
</html>

但不幸的是它不起作用。 我正在使用 Visual Basic 服务器端;客户端我正在使用 javascript。

【问题讨论】:

标签: javascript asp.net forms iframe submit


【解决方案1】:

请试试这个代码

setTimeout(function(){document.location.href = "www.google.com";},500);

也许对你有帮助

【讨论】:

    【解决方案2】:
    document.getElementId('iframe_name').src="http://anothersite.com/";
    

    @benVG: 等等...表单在 iframe inside 中,提交后您希望 相同的 iframe 转到另一个网址吗?如果是这种情况,那么您只需要document.location.url = 'http://someurl.com'。如果是这种情况,您根本不需要对 iframe 的引用。

    【讨论】:

    • 和我写的差不多
    • @benVG:你用你的 iframe 的实际 ID 替换了上面的 'iframe_name' 对吗?
    • @benVG: 等等...表单在 iframe inside 中,提交后您希望 same iframe 转到另一个网址吗?如果是这种情况,那么您只需要document.location.url = 'http://someurl.com'
    猜你喜欢
    • 1970-01-01
    • 2013-04-13
    • 1970-01-01
    • 2012-03-29
    • 2016-12-30
    相关资源
    最近更新 更多