Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi I need to closed IFrame on click of from cancel.

I am Have Cancel Button on Form and opening this form in a iFrame but when i am trying to closed the Iframe then i am getting error
" Blocked a frame with origin from accessing a cross-origin frame"


Uncaught SecurityError: Blocked a frame with origin "http://localhost:55557" from accessing a frame with origin "[^]".
Protocols, domains, and ports must match

this due to Same-origin security policy
what approach i need to follow for closing the Iframe

What I have tried:

Iframe View
-------------------------------------------------------------------------------

@{
ViewBag.Title = "Test";
}



Do it here i am calling onlick event on link and calling "OpenIframe" mehtod!





Test



<script type="text/javascript">

function OpenIframe() {
if (!$('#iframe').length) {
$('#iframeHolder').html('<iframe id="iframe" src="http://localhost:55557/Home/Index" width="700" height="450"></iframe>');
}
return true;
}
</script>


iframe action

C#
public class HomeController : Controller
 {
     //
     // GET: /Home/

     public ActionResult Test()
     {
         return View();
     }

 }


--------------------------------------------------------------

My Form which is opening in Iframe



@model MyView.Models.Home

@{
ViewBag.Title = "Index";
}

Index



@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "signupform" })) {

}



@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
<script>
function Test() {
window.parent.$('#iframe').remove();
}

</script>



My action Method for form

C#
public ActionResult Index()
      {
          return View();
      }
Posted
Updated 14-Oct-16 18:55pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900