网页自动关闭

将【<body 】标签内容复制到网页内容中

<!DOCTYPE html>

<html>

<head>

    <title>自动关闭的网页</title>

</head>

<body onload="setTimeout(closePage, 5000)">

    <script>

        function closePage() {

            window.close();

        }

    </script>

    <p>这个页面将在5秒后自动关闭。</p>

</body>

</html>

判断是否在有效期

function isWithinValidityPeriod(referenceDate, validityDurationInMilliseconds) {

    // 将有效期时长转换为毫秒(如果给出的是天数、小时数等,需要相应转换)

    // 假设validityDurationInMilliseconds是以毫秒为单位

    

    // 获取当前时间的毫秒时间戳

    var currentTime = new Date().getTime();

    

    // 计算有效期结束的时间点

    var endTime = referenceDate.getTime() + validityDurationInMilliseconds;

    

    // 判断当前时间是否在参考时间和有效期结束时间之间

    return currentTime >= referenceDate && currentTime <= endTime;

}


// 使用示例

var startDate = new Date(); // 假设referenceDate是你要检查的有效期开始时间

var validityDays = 7 * 24 * 60 * 60 * 1000; // 有效期7天,转换为毫秒


// 判断当前时间是否在startDate之后的7天内

if (isWithinValidityPeriod(startDate, validityDays)) {

    console.log("当前时间在有效期内!");

} else {

    console.log("当前时间已超过有效期!");

}

自动判断有效期

function isWithinValidityPeriod(referenceDate, validityDurationInMilliseconds) {

    var currentTime = new Date().getTime();

    var endTime = referenceDate.getTime() + validityDurationInMilliseconds;

    return currentTime >= referenceDate && currentTime <= endTime;

}


// 设置有效期的起始时间和有效期长度(例如7天)

var startDate = new Date(); // 假设现在是有效期的开始时间

var validityDays = 7 * 24 * 60 * 60 * 1000; // 有效期7天,转换为毫秒


// 判断并处理

if (!isWithinValidityPeriod(startDate, validityDays)) {

    console.log("当前时间已超过有效期,即将关闭页面...");

    setTimeout(function() {

        window.close();

    }, 1000); // 设置1秒后关闭页面,给予用户阅读提示的时间

} else {

    console.log("当前时间在有效期内。");

}

禁用打印

document.addEventListener('keydown', function(event) {

    if (event.key === 'p' && (event.ctrlKey || event.metaKey)) { // 捕捉Ctrl+P或Cmd+P(Mac)

        event.preventDefault();

        alert("打印功能已被禁用!");

    }

});


window.onbeforeprint = function(event) {

    event.preventDefault();

    return false;

};

相关推荐

  1. 网页自动关闭

    2024-06-13 06:40:05       10 阅读
  2. Postman关闭自动更新程序

    2024-06-13 06:40:05       41 阅读
  3. Python实现电脑自动关机

    2024-06-13 06:40:05       7 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-13 06:40:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-13 06:40:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-13 06:40:05       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-13 06:40:05       20 阅读

热门阅读

  1. 【AI应用探讨】— Meta Llama-3模型应用场景

    2024-06-13 06:40:05       6 阅读
  2. 011.编译随机指纹浏览器-禁用webRTC-售卖成品

    2024-06-13 06:40:05       7 阅读
  3. uni-app文件下载 h5 xls 乱码 锟斤拷 Blob pdf打不开

    2024-06-13 06:40:05       11 阅读
  4. Spring Boot中的RESTful API详细介绍及使用

    2024-06-13 06:40:05       4 阅读
  5. spring boot logback.xml文件配置,info、error隔离

    2024-06-13 06:40:05       11 阅读
  6. MySQL 搭建主从报错 1236

    2024-06-13 06:40:05       7 阅读
  7. vue在hash路由模式下实现点击定位滑动

    2024-06-13 06:40:05       6 阅读
  8. 学习AI 机器学习,深度学习需要用到的python库

    2024-06-13 06:40:05       6 阅读
  9. 深度学习每周学习总结N1(one-hot 编码案例)

    2024-06-13 06:40:05       6 阅读
  10. 人脑神经元与AI神经网络的奥秘

    2024-06-13 06:40:05       9 阅读
  11. Android 10.0 framework层禁止扫描5g wifi功能实现

    2024-06-13 06:40:05       5 阅读