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

1 篇文章 0 订阅
1 篇文章 0 订阅

直接跳转

复制下列代码, 保存文件名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>
VS Code(Visual Studio Code)是一款流行的轻量级代码编辑器,用于多种编程语言包括HTML、CSS和JavaScript。配置它来支持HTML5并确保正常工作,可以按照以下步骤操作: 1. **安装必要的插件**: - 安装HTML/SVG/CSS支持:打开VSCode,点击左上角的扩展图标(齿轮形状),搜索并安装 "Live Server" 和 "HTML Snippets" 插件,它们能提供实时预览和代码提示功能。 - 可选地,安装 "Prettier - Code formatter" 用于格式化代码,保持一致性。 2. **设置默认浏览器**: - 打开用户首选项(`Ctrl + ,` 或 `Cmd + ,`),选择 "User Settings"。 - 在 "settings.json" 文件内添加: ```json "liveServer.browser": "chrome", // 或者其他你想使用的浏览器路径,如 "msedge", "opera" ``` 这样每次保存文件后,Live Server会自动在指定浏览器中刷新页面。 3. **启用代码片段和快捷键**: - 使用 `Ctrl + K` 然后选择 `E HTML`(或相应快捷键)可以快速插入HTML元素模板。 - 对于JavaScript,你可能还需要安装一个JavaScript语言支持插件,例如 "TypeScript" 或 "ESLint"。 4. **设置调试**: - 如果你需要进行Web应用的调试,安装 "Debugger for Chrome" 或 "Debugger for Node.js" 插件。 5. **检查语法错误**: - 安装 "ESLint" 或 "JSHint" 可以实时检测语法错误。 6. **HTML验证**: - 考虑安装 "HTMLHint" 插件来检查HTML结构是否符合标准。 7. **设置文件关联**: - 在 "File Associations" 中确保`.html` 文件关联到VSCode,这样双击即可直接打开编辑器。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Ha-Ha-Interesting

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

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

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

打赏作者

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

抵扣说明:

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

余额充值