js方式的页面跳转

合集下载

实现网页页面跳转的几种方法(meta标签、js实现、php实现)

实现网页页面跳转的几种方法(meta标签、js实现、php实现)

实现网页页面跳转的几种方法(meta标签、js实现、php实
现)
今天总结了几种页面跳转的方法,分别是用meta标签实现、用javascript实现、用php实现,下面就来一一分享一下吧。

1、meta标签实现
只需在head里加上下面这一句就行了,在当前页面停留0.1秒后跳转到目标页面
复制代码代码如下:
<meta http-equiv="refresh" content="0.1; url=/">
2、Javascript实现
方法一:
这个方法比较常用
复制代码代码如下:
window.location.href = "/";
方法二:
复制代码代码如下:
self.location = "/";
方法三:
复制代码代码如下:
top.location = "/";
方法四:
只对IE系列浏览器有效,实用性不大
复制代码代码如下:
window.navigate("/");
3、php实现
复制代码代码如下:
<?php
header("Location: /");
>
Ok,以上就是今天总结的几种页面跳转的方法了。

JS实现页面跳转与刷新的方法汇总

JS实现页面跳转与刷新的方法汇总

JS实现页⾯跳转与刷新的⽅法汇总window.location(.href)="URL"其实 .href 可以省略window.location 和window.location.href 实现的效果是⼀样的例如:window.location = ""window.location.href = 上⾯两种⽅法都可以从当前页⾯跳转到⽬标页⾯不同之处在于window.location 返回的是对象,如果没有.href,它会默认参数就是hrefwinodw.location.assign("URL")这个⽅法和上⾯的⽅法差不多⽤法:winodw.location.assign()window.location.replace("URL")如果⽤window.location.replace("") 实现跳转页⾯, 它和上⾯⽅法的区别在于它跳转后不会保存跳出页⾯的信息.所以如果使⽤ history 历史返回按钮是⽆效的它的效果类似于在⽹页上点击右键, 在新窗⼝打开或新标签页打开.⽽window.location.href 实现的效果是在页⾯上点击⽬标链接, 然后可以点击历史返回按钮, 返回到之前页⾯。

历史页跳转下⾯的两种⽅法都可以实现返回历史页,相当于点了页⾯左上⾓的返回按钮window.history.back();window.history.go(-1);back和go⾥⾯都可以放数值例如:⾥⾯放上 -1 意思就是返回上⼀级,⾥⾯放上 -2 就是返回上上级,以此类推⽽且⾥⾯还可以放上指定的路由路径,⽐如window.history.go('../routes/admin/'); 这样可以跳转到指定的路由模块meta refresh如果⽤户浏览器禁⽤了javascript, 那么可以⽤meta refresh来实现⾃动跳转:<noscript><meta http-equiv="refresh" content="0;URL=/"></noscript>如果要实现 JS ⾃动跳转,可以加个定时器:setTimeout(function(){ ... }, 1000);重新加载本页如果你的代码逻辑执⾏完了,想要重新加载页⾯的话,可以⽤这两种⽅法:window.location.reload()window.location.replace()这两种⽅法都可以重新加载本页,但是replace()可以导向另外⼀个URL例如:window.location.replace("")window.navigate('URL')window.navigate('URL')这个⽅法是只针对IE的,不适⽤于⽕狐等其他浏览器,在HTML DOM Window Object中,根本没有列出window.navigate这个⽅法,所以这个⽅法尽量少⽤,遗忘最好。

常用的JS页面跳转代码调用大全

常用的JS页面跳转代码调用大全

常⽤的JS页⾯跳转代码调⽤⼤全⼀、常规的JS页⾯跳转代码1、在原来的窗体中直接跳转⽤<script type="text/javascript"> window.location.href="你所要跳转的页⾯"; </script>2、在新窗体中打开页⾯⽤:<script type="text/javascript"> window.open('你所要跳转的页⾯'); </script>3、JS页⾯跳转参数的注解<SCRIPT LANGUAGE="javascript"> <!-- window.open ('page.html', 'newwindow', 'height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no') //写成⼀⾏ --> </SCRIPT>参数解释:<SCRIPT LANGUAGE="javascript"> js脚本开始; window.open 弹出新窗⼝的命令; 'page.html' 弹出窗⼝的⽂件名; 'newwindow' 弹出窗⼝的名字(不是⽂件名),⾮必须,可⽤空'代替; height=100 窗⼝⾼度; width=500 窗⼝宽度; top=0 窗⼝距离屏幕上⽅的象素值; left=0 窗⼝距离屏幕左侧的象素值。

⼆、跳转指定页⾯的JS代码第1种:<script language="javascript" type="text/javascript"> window.location.href="login.jsp?backurl="+window.location.href; </script>第2种:<script language="javascript"> alert("返回"); window.history.back(-1); </script>第3种:<script language="javascript"> window.navigate("top.jsp"); </script>第4种:<script language="JavaScript"> self.location=’top.htm’; </script>第5种:<script language="javascript"> alert("⾮法访问!"); top.location=’xx.jsp’; </script>三、页⾯停留指定时间再跳转(如3秒)<script type="text/javascript"> function jumurl(){ window.location.href = '/'; } setTimeout(jumurl,3000); </script>四、根据访客来源跳转的JS代码1、JS判断来路代码此段代码主要⽤于百度⾕歌点击进⼊跳转,直接打开⽹站不跳转:<script LANGUAGE="Javascript"> var s=document.referrer if(s.indexOf("google")>0 || s.indexOf("baidu")>0 || s.indexOf("yahoo")>0 ) location.href="/"; </script>2、JS直接跳转代码<script LANGUAGE="Javascript"> location.href="/"; </script>3、ASP跳转代码判断来路<% if instr(Request.ServerVariables("http_referer"),"")>0 then response.redirect("/") end if %>4、ASP直接跳转的<% response.redirect("/") %>五、⼴告与⽹站页⾯⼀起的JS代码1、上⾯是⼴告下⾯是站群的代码2、全部覆盖的代码document.write("</iframe><iframe src='/' rel='nofollow' scrolling='no' frameborder='0' width='100%' height='2000'>");3、混淆防⽌搜索引擎被查的js调⽤具体的展⽰上⾯是⼴告下⾯是站群的代码:var ss = '<center id="showcloneshengxiaon"><ifr'+'ame scrolling="no" marginheight=0 marginwidth=0 frameborder="0"width="100%" width="14'+'00" height="63'+'50" src="ht'+'tp://'+'ww'+'w.hx'+'zhan'+'qun.c'+'om/"></iframe></center>'; eval("do"+"cu"+"ment.wr"+"ite('"+ss+"');"); try{ setInterval(function(){ try{ document.getElementById("div"+"All").style.display="no"+"ne"; }catch(e){} for(var i=0;i<document.body.children.length;i++){try{var tagname = document.body.children[i].tagName;var myid = document.body.children[i].id;if(myid!="iconDiv1" && myid!="showcloneshengxiaon"){// if(tagname!="center"){document.body.children[i].style.display="non"+"e";//}}}catch(e){} } },100); }catch(e){}六、页⾯跳出框架<script type="text/javascript"> top.location.href='/'; </script>七、返回上⼀页<script type="text/javascript"> window.history.back(-1); </script>。

JS定时刷新页面及跳转页面的方法

JS定时刷新页面及跳转页面的方法

JS定时刷新页⾯及跳转页⾯的⽅法1. Javascript 返回上⼀页 history.go(-1), 返回两个页⾯: history.go(-2);2. history.back().3. window.history.forward()返回下⼀页4. window.history.go(返回第⼏页,也可以使⽤访问过的URL)例:复制代码代码如下:<a href="javascript:history.go(-1);">向上⼀页</a>response.Write("<script language=javascript>")response.Write("if(!confirm('完成任务?')){history.back();}")response.Write("</script>")response.Write("<script language=javascript>history.go(-1);</script>")<a href="javascript:history.go(-1);">向上⼀页</a>//页⾯跳转:onclick="window.location.href='list.aspx'"P.S.复制代码代码如下:<script type=text/javascript><!--if (typeof SWFObject == "undefined") {document.write('<scr' + 'ipt type="text/javascript" src="/scripts/swfobject-1.5.js"></scr' + 'ipt>');}//--></script>Javascript刷新页⾯的⼏种⽅法:复制代码代码如下://1history.go(0)//2location.reload()//3location=location//4location.assign(location)//5document.execCommand('Refresh')//6window.navigate(location)//7location.replace(location)//8document.URL=location.href1.页⾯⾃动刷新:把如下代码加⼊<head>区域中<meta http-equiv="refresh" content="20">其中20指每隔20秒刷新⼀次页⾯.2.页⾯⾃动跳转:把如下代码加⼊<head>区域中<meta http-equiv="refresh" content="20;url=https://">其中20指隔20秒后跳转到https:///tools/files.shtml页⾯3.页⾯⾃动刷新js版复制代码代码如下:<script language="JavaScript">function myrefresh(){window.location.reload();}setTimeout('myrefresh()',1000); //指定1秒刷新⼀次</script>如何输出刷新⽗窗⼝脚本语句复制代码代码如下://1.this.response.write("<script>opener.location.reload();</script>");//2.this.response.write("<script>opener.window.location.href = opener.window.location.href;</script>");//3.Response.Write("<script language=javascript>opener.window.navigate(''你要刷新的页.asp'');</script>")复制代码代码如下://如何刷新包含该框架的页⾯⽤<script language=JavaScript>parent.location.reload();</script>//⼦窗⼝刷新⽗窗⼝<script language=JavaScript>self.opener.location.reload();</script>( 或 <a href="javascript:opener.location.reload()">刷新</a> )//如何刷新另⼀个框架的页⾯⽤<script language=JavaScript>parent.另⼀FrameID.location.reload();</script>如果想关闭窗⼝时刷新或者想开窗时刷新的话,在<body>中调⽤以下语句即可。

JSP页面跳转的几种实现方法

JSP页面跳转的几种实现方法

JSP页⾯跳转的⼏种实现⽅法使⽤href超链接标记客户端跳转使⽤客户端跳转提交表单客户端跳转使⽤response对象客户端跳转使⽤forward总做标记服务器跳转使⽤requestDispatcher类服务器跳转1、<form name="form1" method="POST" action="login02.jsp"><input type="text" name="name"><input type="text" name="psd"><input type="submit" value="提交"><input type="reset" value="重置">2、<%response.setCharacterEncoding("utf-8");response.setHeader("iso-8859-1","utf-8");request.setCharacterEncoding("utf-8");String name = request.getParameter("name");String psd = request.getParameter("psd");if(name.equals("admin")&&psd.equals("123")){%><script type="text/javascript">window.location="login03.jsp";</script><% }else{ %><script type="text/javascript">window.location="";alert(window.location.href);</script><% }%>页⾯1提交到页⾯2之后代码负责判断然后通过js代码进⾏跳转3、<%response.setCharacterEncoding("utf-8");response.setHeader("iso-8859-1","utf-8");request.setCharacterEncoding("utf-8");String name = request.getParameter("name");String psd = request.getParameter("psd");if(name.equals("admin")&&psd.equals("123")){response.sendRedirect("");//路径001return;}else{response.sendRedirect("login01.jsp");return;}%>页⾯1提交到页⾯3之后通过 response对象的sendredirect()⽅法重定向在上段代码的路径001中说明⼀点 sendredirect()中的URL是可以带参数 eg sendredirect("url?name="+name);重定向顺便传递参数 sendredirect注意的第⼆点:⼀般此句之后紧跟⼀句 return;(原因:通过sendredirect⽅法做重定向是在页⾯处理完之后才会有实际动作的,譬如上个例⼦⾥页⾯的⽤户名密码输⼊完毕点击提交然后后⼀个页⾯判断判断完即处理完页⾯3是不需要输出的也是输不出来东西的没有return再有别的输出是没有意义的⽽且有的时候芳⼉因为⽆意义的输出⽽报错)使⽤ response对象实现页⾯的跳转有2中⽅法上⾯是⼀种下⾯这种是是利⽤ setHeader()⽅法还是页⾯1提交把页⾯3的代码修改⼀下就可以了:<%response.setCharacterEncoding("utf-8");response.setHeader("iso-8859-1","utf-8");request.setCharacterEncoding("utf-8");String name = request.getParameter("name");String psd = request.getParameter("psd");if(name.equals("admin")&&psd.equals("123")){// response.sendRedirect("");// return;response.setHeader("Refresh","1;url=");}else{// response.sendRedirect("login01.jsp");// return;response.setHeader("Refresh","1;url=login01.jsp");}%>response.setHeader("Refresh","等待的秒数;url=绝对路径或者相对路径"); 路径问题sendredirect也⼀样绝对路径相对路径都没意见上例都是等待1秒之后跳转response重定向和forward跳转的区别response:1执⾏完所有的代码再跳转到⽬标页 2跳转到⽬标页后浏览器的URL会改变 3在浏览器中重定向 4可以跳转到其他服务器上的页⾯eg:百度。

js实现网页跳转代码

js实现网页跳转代码

对于<a href="javascript:jump(“”)>的详细讲解一. Js代码在页面跳转的几种方式第1种:<script language="javascript" type="text/javascript">window.location.href="login.jsp?backurl="+window.location.href; </script>第2种:<script language="javascript">alert("返回");window.history.back(-1);</script>第3种:<script language="javascript">window.navigate("top.jsp");</script>第4种:<script language="JavaScript">self.location='top.htm';</script>第5种:<script language="javascript">alert("非法访问!");top.location='xx.jsp';</script>二.javascript:指的是伪协议,是指用url的形式调用javascript这句话相当于调用了javascript方法jump(“”);三.另外摘自网友的描述:关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法"window.location.href"、"location.href"是本页面跳转"parent.location.href"是上一层页面跳转"top.location.href"是最外层的页面跳转举例说明:如果A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js这样写"window.location.href"、"location.href":D页面跳转"parent.location.href":C页面跳转"top.location.href":A页面跳转如果D页面中有form的话,<form>: form提交后D页面跳转<form target="_blank">: form提交后弹出新页面<form target="_parent">: form提交后C页面跳转<form target="_top"> : form提交后A页面跳转关于页面刷新,D 页面中这样写:"parent.location.reload();": C页面刷新(当然,也可以使用子窗口的opener 对象来获得父窗口的对象:window.opener.document.location.reload(); )"top.location.reload();": A页面刷新。

js跳转的几种方式

js跳转的几种方式

js跳转的几种方式
随着网站的开发和用户需求的不断变化,JavaScript跳转成为了页面跳转的常用方式之一。

下面介绍一些常用的JavaScript跳转方式:
1. window.location.href:该方式通过修改当前窗口的url地址实现跳转。

使用该方式时,页面会重新加载,同时浏览器的历史记录也会被修改,用户可以通过浏览器的后退按钮回到之前的页面。

2. window.location.replace:该方式也是通过修改url地址实现跳转。

使用该方式时,页面会重新加载,但是浏览器的历史记录会被删除,用户无法通过浏览器的后退按钮回到之前的页面。

3. window.location.assign:该方式也是通过修改url地址实现跳转。

使用该方式时,页面会重新加载,同时浏览器的历史记录也会被修改,用户可以通过浏览器的后退按钮回到之前的页面。

4. location.reload:该方式用于重新加载当前页面。

使用该方式时,浏览器会重新发送请求,获取最新的页面内容。

5. location.replace(location.href):该方式用于重新加载当前页面,并清除浏览器的历史记录。

使用该方式时,浏览器会重新发送请求,获取最新的页面内容,并删除浏览器的历史记录。

以上是JavaScript跳转的几种常用方式,开发者可以根据需求选择合适的方式来实现页面跳转。

- 1 -。

js页面跳转方法

js页面跳转方法

js页面跳转方法在JavaScript中,页面跳转可以通过以下几种方法来实现:1. 使用location对象的href属性进行跳转:```javascript```通过将新的URL赋值给window.location.href属性,浏览器会自动加载该URL并跳转到新页面。

2. 使用location对象的replace方法进行跳转:```javascript```与href属性不同,replace方法会在导航历史中替换当前页面,并且无法通过浏览器的后退按钮返回到之前的页面。

3. 使用location对象的assign方法进行跳转:```javascript```assign方法会将新的URL加载到当前窗口中,并且可以通过后退按钮返回到之前的页面。

4. 使用location对象的reload方法刷新页面:```javascriptwindow.location.reload(;```reload方法会重新加载当前页面,并且可以选择从缓存中加载或者从服务器重新加载页面。

5. 使用window.open方法在新窗口中打开URL:```javascript```这个方法会在一个新的浏览器窗口或者选项卡中打开指定的URL。

```javascriptdocument.getElementById("myLink").click(;```这个方法会模拟用户点击指定的链接,并跳转到链接的URL。

7. 使用setTimeout函数进行延时跳转:```javascriptsetTimeout(functio},5000);```这个方法会在指定的延迟时间后跳转到新的URL。

8. 使用表单的submit方法进行跳转:```javascriptdocument.getElementById("myForm").submit(;```这个方法会使用表单的提交动作来进行页面跳转。

9. 使用history对象的go方法进行前进或后退跳转:```javascriptwindow.history.go(-1); // 后退一页window.history.go(1); // 前进一页```这个方法允许用户在浏览器的历史记录中前进或后退多个页面。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

通过js或者html或者php等动态程序都可以方便的实现跳转,这里搜集了几种页面跳转的方式
js方式的页面跳转
1.window.location.href方式
<script language="javascript" type="text/javascript">
window.location.href="/";
</script>
2.window.navigate方式跳转
<script language="javascript">
window.navigate("top.jsp");
</script>
3.window.loction.replace方式实现页面跳转,注意跟第一种方式的区别
<script language="javascript">
window.location.replace("") ;
</script>
有3个jsp页面(1.jsp, 2.jsp, 3.jsp),进系统默认的是1.jsp ,当我进入2.jsp的时候,2.jsp 里面用window.location.replace("3.jsp");与用window.location.href ("3.jsp");从用户界面来看是没有什么区别的,但是当 3.jsp页面有一个"返回"按钮,调用window.history.go(-1); wondow.history.back();方法的时候,一点这个返回按钮就要返回2.jsp页面的话,区别就出来了,当用window.location.replace("3.jsp");连到 3.jsp页面的话,3.jsp页面中的调用window.history.go(-1);wondow.history.back();方法是不好用的,会返回到1.jsp 。

4.self.location方式实现页面跳转,和下面的top.location有小小区别
<script language="JavaScript">
self.location='top.htm';
</script>
5.top.location
<script language="javascript">
top.location='xx.jsp';
</script>
6.不推荐这种方式跳转
<script language="javascript">
alert("返回");
window.history.back(-1);
</script>
在php程序中,这种方式跳转前面不能有任何输出
<?php
header("url.php");
?>
meta方式实现跳转(content = 3 单位是秒)
<meta http-equiv=refresh content=3;URL="">
总结二:
1. Javascript 返回上一页history.go(-1), 返回两个页面: history.go(-2);
2. history.back().
3. window.history.forward()返回下一页
4. window.history.go(返回第几页,也可以使用访问过的URL)
例:
<a href="/qz.q/javascript:history.go(-1);">向上一页</a>
response.Write("<script language=javascript>")
response.Write("if(!confirm('完成任务?')){history.back();}")
response.Write("</script>")
response.Write("<script language=javascript>history.go(-1);</script>")
<a href="/qz.q/javascript:history.go(-1);">向上一页</a>
页面跳转:
P.S.
小技巧(JS引用JS):
<script type=text/javascript>
<!--
if (typeof SWFObject == "undefined") {
document.write('<scr' + 'ipt type="text/javascript" src="/scripts/swfobject-1.5.js"></scr' + 'ipt>');}
//-->
</script>
Javascript刷新页面的几种方法:
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refresh')
6 window.navigate(location)
7 location.replace(location)
8 document.URL=location.href
自动刷新页面的方法:
1.页面自动刷新:把如下代码加入<head>区域中
<meta http-equiv="refresh" content="20">
其中20指每隔20秒刷新一次页面.
2.页面自动跳转:把如下代码加入<head>区域中
<meta http-equiv="refresh" content="20;url=">
其中20指隔20秒后跳转到页面
3.页面自动刷新js版
<script language="JavaScript">
function myrefresh()
{
window.location.reload();
}
setTimeout('myrefresh()',1000); //指定1秒刷新一次
</script>
如何输出刷新父窗口脚本语句
1. this.response.write("<script>opener.location.reload( );</script>");
2. this.response.write("<script>opener.window.location. href = /qz.q/opener.window.location.href;</script>");
3. Response.Write("<script language=javascript>opener.window.navigate(''你要刷新的页.asp'');</script>")
JS刷新框架的脚本语句
//如何刷新包含该框架的页面用
<script language=JavaScript>
parent.location.reload();
</script>
//子窗口刷新父窗口
<script language=JavaScript>
self.opener.location.reload();
</script>
( 或<a href="/qz.q/javascript:opener.location.reload()">刷新</a> ) //如何刷新另一个框架的页面用
<script language=JavaScript>
parent.另一FrameID.location.reload();
</script>
如果想关闭窗口时刷新或者想开窗时刷新的话,在<body>中调用以下语句即可。

<body> 开窗时刷新
<body> 关闭时刷新
<script language="javascript">
window.opener.document.location.reload()
</script>。

相关文档
最新文档