哪个是更好的方法window.parent.location.href或window.top.location [英] Which one is better approach window.parent.location.href or window.top.location

查看:645
本文介绍了哪个是更好的方法window.parent.location.href或window.top.location的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中工作,在这种情况下,必须在特定情况下在错误页面"上进行重定向.为此,我创建了Error.aspx页面.现在我正在使用 window.top.location.href ="../Error.aspx"并生成 http://localhost/app_web/Error.aspx ,它的工作正常,只有一次(显示消息 http://xyz/ErrorPage.aspx '不存在.) .所以任何人都可以建议哪个是更好的选择.

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.

谢谢

推荐答案

top优于parent,因为您的页面可能位于框架内部本身就是一个框架.

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.location.href或window.top.location的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆