location.href使用方法总结

javascript中的location.href有非常多种使用方法,主要例如以下。

self.location.href=”/url” 当前页面打开URL页面

location.href=”/url” 当前页面打开URL页面

windows.location.href=”/url” 当前页面打开URL页面,前面三个使用方法同样。

this.location.href=”/url” 当前页面打开URL页面

parent.location.href=”/url” 在父页面打开新页面

top.location.href=”/url” 在顶层页面打开新页面

假设页面中自己定义了frame,那么可将parent self top换为自己定义frame的名称,效果是在frame窗体打开url地址

此外,window.location.href=window.location.href;和window.location.Reload()和都是刷新当前页面。差别在于是否有提交数据。当有提交数据时,window.location.Reload()会提示是否提交,window.location.href=window.location.href;则是向指定的url提交数据


http://www.zhongsisi.com/location-href/


原文地址:https://www.cnblogs.com/hrhguanli/p/3920224.html