网站地图    收藏   

主页 > 前端 > javascript >

javascript中location.href地址跳转详解

来源:自学PHP网    时间:2014-09-19 14:48 作者: 阅读:

[导读] 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

/

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论