双击html或cmd文件后, 自动打开网站的方法

直接跳转

复制下列代码, 保存文件名xxx.html或者cmd, 之后双击文件名, 即可自动打开网页

方法1

保存为xxx.html

<script language="javascript" type="text/javascript">   
// 以下方式直接跳转  
window.location.href='http://www.weather.com.cn/forecast/';  
</script>  

方法2

保存为xxx.html

<head>  
<!-- 以下方式定时转到其他页面 -->  
<meta http-equiv="refresh" content="5;url=http://www.weather.com.cn/forecast/">   
</head> 

方法3

保存为xxx.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
</head>
<body>
    <script>
    <!-- 添加URL到下面 -->
        window.location.href = "http://www.weather.com.cn/forecast/";
    </script>
</body>
</html>

方法4

保存为xxx.cmd或者xxx.cmd

@ECHO off
START http://www.cma.gov.cn/
REM explorer http://www.cma.gov.cn/
REM start chrome.exe "http://www.cma.gov.cn/"
REM START iexplore.exe "http://www.cma.gov.cn/"

定时跳转

方法1

保存为xxx.html.

<script language="javascript" type="text/javascript">   
// 以下方式定时跳转, 5s 后跳转
setTimeout("javascript:location.href='http://www.weather.com.cn/forecast/'", 5000);   
</script>  

方法2

保存为xxx.html.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	window.onload = function(){
		var time = 5;
		var secondEle = document.getElementById("second");
		var timer = setInterval(function(){
			secondEle.innerHTML = time;
			time--;
			if(time==0){
				clearInterval(timer);
				location.href="http://www.weather.com.cn/forecast/";
			}
				
		},1000);
	}
</script>
</head>
<body>
	<span style="color:red" id="second">5</span>秒钟后跳转,如不跳转点击<a href="http://www.weather.com.cn/forecast/">这里</a>!
</body>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ha-Ha-Interesting

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值