Home > Web Front-end > JS Tutorial > How to jump to the page through the prompt box in JavaScript_javascript skills

How to jump to the page through the prompt box in JavaScript_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:15:43
Original
1019 people have browsed it

The specific code to jump to the page through the prompt box is as follows:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-">
<title>Document</title>
</head>
<body>
<script>
window.onload = function(){ //设置当页面加载时执行
var btn =document.getElementsByTagName("button")[] //获取btn元素
btn.onclick = function(){ //给button加上一个点击事件
var answer = confirm("是否想游览ziksang博客园") //把确认框赋值给answer
if(answer) //判断是否点击确定
window.location ="http://www.cnblogs.com/Ziksang/" //确定的话游览器自身跳转
}
}
</script>
<button>点击跳转</button>
</body>
</html>
Copy after login

The following will introduce you to several common js ways to implement page jumps

First type:

<script language="javascript" type="text/javascript">
window.location.href="login.jsp&#63;backurl="+window.location.href; 
</script>
Copy after login

Second type:

<script language="javascript">
alert("返回");
window.history.back(-1);
</script>
Copy after login

Third type:

<script language="javascript">
window.navigate("top.jsp");
</script>
Copy after login

The fourth type:

<script language="JavaScript">
self.location='top.htm';
</script>
Copy after login

The fifth type:

<script language="javascript">
alert("非法访问!");
top.location='xx.jsp';
</script>
Copy after login

Then I will introduce to you several ways to use pop-up windows in js to achieve page jumps

——————————————————————————————————

The first method: Pop up the selection box to jump to other pages

<script language="javascript"> 
<!-- 
function logout(){ 
if (confirm("你确定要注销身份吗?是-选择确定,否-选择取消"))...{ 
window.location.href="/logout.asp&#63;act=logout" 
} 
} 
--> 
</script> 
<input type="button" onclick="logout()" value="注销"/>
Copy after login

Second type: Pop up prompt box to jump to other pages

<script language="javascript"> 
<!-- 
function logout(){ 
alert("你确定要注销身份吗?"); 
window.location.href="/logout.asp&#63;act=logout" 
} 
--> 
</script>
<input type="button" onclick="logout()" value="注销"/>
Copy after login

The page automatically jumps to other pages
——————————————————————————————————

Just add one line of code to the page

<meta http-equiv="Refresh" content="5; url=http://www.codepub.com" />
Copy after login

Among them, the 5 in content="5; url=http://www.codepub.com" means jumping after 5 seconds and can be directly set to 0

This code is mostly used for page jumps when users log in

Put onClick="windows.open("Submit.html")"

changed to

onClick="window.location.reload('Submit.html');"
window.open('Submit.html')
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template