location.href在js中有很多中用法主要是控制页面或上级框架页面跳转的一些方法,下面我给大家整理了location.href地址跳转参数介绍希望对各位有帮助。 javascript中的location.href有很多种用法,主要如下。 top.location.href=”url” 在顶层页面打开url(跳出框架) self.location.href=”url” 仅在本页面打开url地址 parent.location.href=”url” 在父窗口打开Url地址 this.location.href=”url” 用法和self的用法一致 location.href=”/url” 当前页面打开URL页面 windows.location.href=”/url” 当前页面打开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提交数据 location之页面跳转js如下: 代码如下 | 复制代码 | //简单跳转 function gotoPage(url) { // eg. var url = 'newsview.html?catalogid='+catalogID+'&pageid='+pageid; window.location = url; } // 对location用法的升级,为单个页面传递参数 function goto_catalog(iCat) { if(iCat<=0) { top.location = '../index.aspx'; // top出去 } else { window.location = '../newsCat.aspx?catid='+iCat; } } // 对指定框架进行跳转页面,二种方法皆可用 function goto_iframe(url) { parent.mainFrame.location = '../index.aspx'; // // parent.document.getElementById('mainFrame').src = '../index.aspx';// use dom to change page // 同时我增加了dom的写法 } // 对指定框架进行跳转页面,因为 parent.iframename.location='../index.aspx'; 方法不能实行,主要是 'parent.iframename' 中的iframename在js中被默认为节点,而不能把传递过来的参数转换过来,所以用dom实现了该传递二个参数的框架跳转页面,希望那位仁兄不吝赐教! function goto_iframe(iframename,url) { parent.document.getElementById(iframename).src = '../index.aspx';// use dom to change page by iframeName //} // 回到首页 function gohome() { top.location = '/index.aspx'; }
|
|