2013-10-21 29 views
0

我有一个在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; 
}); 

+1

同一个域中是否都有父级和iframe文档? – Kaf

+0

是的...但我想重定向到另一个域上的另一个页面 – sirbombay

+0

好的,你可以有任何重定向页面,但能够访问iframe中的父文档使用JavaScript都应该在同一个域。 – Kaf

回答

1

使用纯JavaScript,iframe的页面内,以下行将重定向/替换父窗口:

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