Which one is better for window.parent.location.href or window.top.location

I work in a project where I have to redirect errors to a page in a specific scenario. To do this, I created the Error.aspx page. Right now I am using window.top.location.href = "../Error.aspx" and it generates http: //localhost/app_web/Error.aspx and its working fine except for one (which shows the message http: // xyz /ErrorPage.aspx 'does not exist.). So can anyone suggest which option is better for this.

thank

+5
source share
3 answers

top ", " parent, , , , .

, :

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;
+9

window.parent . , ..

window.top ; window.parent.parent.parent[...];

, , , , , :

window.location.href = "../Error.aspx";

. window.parent, window.top window.location.

+9

, .

  • window.parent.location

    .

  • window.top.location

    • "".
    • It returns the location of the topmost window in the window hierarchy.
    • If there is no parent in the window, top is a reference to itself (window === window.top)
+5
source

All Articles