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>

posted @ Friday, March 19, 2010 6:34 AM
Print

Comments on this entry:

# re: JavaScript function to Redirect parent of IFrame to specified URL

Left by Sonja Kathryna at 6/2/2011 3:55 PM
Gravatar
Thanks for the code! I look forward to giving it a try.

# re: JavaScript function to Redirect parent of IFrame to specified URL

Left by xcv xvx at 1/7/2012 7:02 PM
Gravatar
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);
}

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«May»
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789