第一种:(跳转到haha.html) <script language="javascript" type="text/javascript"> window.location.href="haha.html"; </script> 第二种:(返回上一页面) <script language="javascript"> window.history.go(-1); </script> 第三种: <script language="javascript"> window.navigate("haha.html"); </script> 第四种: <script language="JavaScript"> self.location="haha.html"; </script> 第五种: <script language="javascript"> top.location="haha.html"; </script>哈哈,自己要是不会用可以看代码:
这是你要的页面,里面还有简单的参数传递。自己可以看看。不会的可以留言哦。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" id="btn" value="哈哈" />
</body>
<script type="text/javascript">
btn.onclick = function(){
top.location="haha.html";
// window.location.href ="https://www.baidu.com/";
// window.location.href ="haha.html?id=1&name=666";
// window.location.href ="haha.html#id=1&name=666";
}
</script>
</html>
在写一个haha.html页面代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h2>回去了</h2>
</body>
<script type="text/javascript">
document.querySelector("h2").onclick = function(){
window.history.go(-1)
}
var x = window.location.href;
var y = window.location.hash;
console.log(x)
console.log(y)
// console.log(window.location.host)
console.log(location.hostname)
console.log(location.pathname)
console.log(location.search)
</script>
</html>