问题描述
谁能告诉我之间的差异 window.location.href
和 top.location.href
?
Can Anyone tell me the difference between window.location.href
and top.location.href
?
和同样在哪里使用哪一个。
And also where to use which one.
和这MVC Ajax调用后重定向当一个会更好?
And which one will be better when redirecting after an ajax call in mvc?
推荐答案
window.location.href
返回当前页面的位置。
window.location.href
returns the location of the current page.
top.location.href
(这是 window.top.location.href
的别名)返回在窗口层次结构中最上层的窗口的位置。如果窗口没有父,顶
是对自身的引用(换句话说,窗口
=== window.top
)。
top.location.href
(which is an alias of window.top.location.href
) returns the location of the topmost window in the window hierarchy. If a window has no parent, top
is a reference to itself (in other words, window
=== window.top
).
顶
是非常有用的都当你处理框架,并已被其他网页打开的窗口的时候。例如,如果你有一个名为页的test.html
与下面的脚本:
top
is useful both when you're dealing with frames and when dealing with windows which have been opened by other pages. For example, if you have a page called test.html
with the following script:
var newWin=window.open('about:blank','test','width=100,height=100');
newWin.document.write('<script>alert(top.location.href);</script>');
由此产生的警报将有完整路径的test.html&ndash的; 不会关于:空白,这是什么 window.location.href
将返回
The resulting alert will have the full path to test.html – not about:blank, which is what window.location.href
would return.
要回答你的问题有关重定向,去与 window.location.assign(URL);
To answer your question about redirecting, go with window.location.assign(url);
这篇关于window.location.href和top.location.href的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!