javascript的几种跳转方式

版权声明:转载博文请注明出处。 https://blog.csdn.net/weixin_41297332/article/details/85345544

1.window对象的open函数

window.open("url")

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>js的三种跳转方式</title>
	<style>
		button{
			display: block;
			width: 100px;
			height: 70px;
			margin: 200px auto;
		}
	</style>
</head>
<body>
	<button onclick="fun()">跳转</button>
	<script>
		function fun() {
			window.open("http://www.baidu.com/");
		}
	</script>
</body>
</html>

2.自定义函数
 

<script>
    function openWin(obj) {
			obj.target = "_blank";
			obj.href = "http://www.baidu.com/";
			obj.click();
		}
</script>

<a href="javascript:void(0)" onclick="openWin(this)">点击</a>

3.通过window对象的location属性


window.location.href = "http://www.baidu.com/"

猜你喜欢

转载自blog.csdn.net/weixin_41297332/article/details/85345544
今日推荐