首页IT科技js如何跳转网页(js跳转(js跳转网页))

js如何跳转网页(js跳转(js跳转网页))

时间2025-06-14 14:25:07分类IT科技浏览3983
导读:如何使用js跳转代码 javascript常用的页面跳转方法为:...

如何使用js跳转代码

javascript常用的页面跳转方法为:

window.location.href=some_url;

下面举例演示点击按钮后             ,延迟3秒跳转页面:

1             、HTML结构

2                     、javascript代码

functionfun(){

setTimeout(function(){

window.location.href="

},3000);

js中有哪些方式可以实现页面的跳转

1      、改变当前页面的url实现跳转:例如

window.location="

2         、在当前窗口打开新页面也可以实现页面跳转:

window.open("

",_self);

JS跳转大概有以下几种方式: 第一种:(跳转到b.html)

<script language="javascript" type="text/javascript"> window.location.href="b.html"; </script>

第二种:(返回上一页面)

<script language="javascript"> window.history.go(-1); </script>

第三种:

<script language="javascript"> window.navigate("b.html"); </script>

第四种:

<script language="JavaScript"> self.location=’b.html’; </script>

第五种:

<script language="javascript"> top.location=’b.html’; </script>

页面传值:

第一个页面 <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <SCRIPT LANGUAGE="JavaScript"> function test(){ var s = document.getElementById("txt"); location.href="test2.html?"+"txt="+encodeURI(s.value); } </SCRIPT> <body> <input type="text" id="txt"> </br> <input type="button" value="TEST" onclick="test()"/> </body> </html>

第二个页面

<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <script language="javascript" type="text/javascript"> var loc = location.href; var n1 = loc.length;//地址的总长度 var n2 = loc.indexOf("=");//取得=号的位置 var id = decodeURI(loc.substr(n2+1, n1-n2));//从=号后面的内容 alert(id); //document.write(id) </script> </body> </html>

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
go语言包管理(Groovy闭包深入学习 [203] 一直都有新高度 ITeye技术网站) npm命令大全(10分钟内讲解Npm脚本使用教程)