I am working in a project where I have to redirect on Error Page in a particular scenario. For that I have created Error.aspx page. Right now I am using window.top.location.href = "../Error.aspx" and it generate http://localhost/app_web/Error.aspx and its working fine except once (which shows Message http://xyz/ErrorPage.aspx' does not exist. ). So can anyone suggest which is the better option for this.
Thanks
top
is "better than" parent
if your intent is to framebust your page into the top level, because your page may be inside a frame that is itself inside a frame.
As for your relative path problem, you may want to try:
var local = location.pathname.split("/");
local.pop(); // remove the filename
local.pop(); // remove the containing directory
local.push("Error.aspx");
local = location.protocol+"//"+location.hostname+"/"+local.join("/");
top.location.href = local;
window.parent
refers to the parent window of the current window. That parent may have it's own parent, which has its own parent etc.
window.top
refers to this top most window; e.g. window.parent.parent.parent[...]
;
In this circumstance however, you probably only want to redirect the current window, e.g;
window.location.href = "../Error.aspx";
For more info, see the documentation on window.parent
, window.top
and window.location
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With