JavaScript function to Redirect parent of IFrame to specified URL

    /// <summary>
   /// Redirects parent of IFrame to specified URL
   /// If current page doesn’t have parent, redirect itself
   /// </summary>
   /// <param name=”page”></param>
   /// <param name=”url”></param>
   public static void NavigateParentToUrl(Page page, string url)
   {
    String script = @”
try
{
var sUrl='” + url + @”‘;
if (self.parent.frames.length != 0)
    self.parent.location=sUrl;
else
  self.location = sUrl;
}
catch (Exception) {}
“;
    page.ClientScript.RegisterStartupScript(TypeForClientScript(), MethodBase.GetCurrentMethod().Name, script, true);
   }
   /// <summary>