从框架内部重定向到外部页面并“清除框架”

redirect from inside a frame to external page and "clear the frame"

本文关键字:框架 清除 清除框架 内部 重定向 外部      更新时间:2023-09-26

我有一个应用程序,可以在iframe中加载页面。一切正常,但我正处于需要重定向到另一个站点的阶段,它仍在加载这个"外部站点在我的框架内"......这不是我想要的。我如何摆脱框架,因为我不再需要它。

这是我正在重定向的控制器操作:

      public ActionResult Finish()
    {
        if(!string.IsNullOrEmpty(Url))
        {
            string url = string.Format("{0}?code={1}",Url,code);
            return Redirect(url);
        }
        return RedirectToAction("Index");
    }

我在我的视图中添加了 iframe,如下所示:

 <div>    
 <iframe id="paymentFrame" width="600px" height="670px" scrolling="auto" frameborder="0" src='@Url.Action("myForm")'></iframe>
  </div>
  <script type="text/javascript">
 function sendISWPostData() {
     $("#paymentFrame").load(function () {
         var doc = this.contentDocument;
         var form = doc.getElementById('form1');
         var actionUrl = '@ViewBag.WebPayUrl';
         form.action = actionUrl;
         $(this).contents().find(':input[name=cust_name]').val('@ViewBag.CustName');
         $(this).contents().find(':input[name=cust_id]').val('@ViewBag.CustNumber');
         form.submit();
         //return true;

     });   //end load
 }  // end send
 $(document).ready(function () {
 sendISWPostData();
 //return true;
});

使用纯javascript,在iframe页面中,以下行将重定向/替换父窗口:

self.parent.location.replace('www.google.com');