从web服务器中的javascript自动编辑网页

从web服务器中的javascript自动编辑网页,javascript,Javascript,我有一个web服务器有大约20个网页,现在我想要一个javaScript,它可以自动重定向我从第1页->第2页->第3页等等,在一定的时间间隔后,我应该使用什么方法?有人能帮我吗? 使用javascript从一个页面导航到另一个页面,而不使用锚标记。 查看源代码(如下)。 您可以使用此函数放置自己的方法,并在需要的任何时间或时段导航到目标页面 如果有帮助,请标记为已回答。您可以使用HTML元刷新或使用JavaSript设置window.location.href:在每个页面上添加元标

我有一个web服务器有大约20个网页,现在我想要一个javaScript,它可以自动重定向我从第1页->第2页->第3页等等,在一定的时间间隔后,我应该使用什么方法?有人能帮我吗?


使用javascript从一个页面导航到另一个页面,而不使用锚标记。


查看源代码(如下)。
您可以使用此函数放置自己的方法,并在需要的任何时间或时段导航到目标页面
如果有帮助,请标记为已回答。您可以使用HTML元刷新或使用JavaSript设置window.location.href:

在每个页面上添加元标记,如

// page 1 
<meta http-equiv="refresh" content="2;url=http://urdomain.com/page2.htm">

// page 2
<meta http-equiv="refresh" content="2;url=http://urdomain.com/page3.htm">

// page 3
<meta http-equiv="refresh" content="2;url=http://urdomain.com/page4.htm">

.....
//第1页
//第2页
//第3页
.....
语法中的第2条是在2分钟后刷新

JS方法:

  • 使用document.location.href获取url
  • 修改此url字符串以获取下一页
  • 设置
    location.href=“新建url”
  • 在所有页面上添加此脚本

  • 如果要在某个时间间隔后自动重定向,则需要和的组合

    e、 g


    下面是一个javascript实现。它使用onload在加载所有资产后启动。它使用您想要浏览的路径数组,并使用
    page\u duration
    变量来确定何时切换到下一页

    window.onload = function() {
        // array of all the paths to the pages you have
        var paths = ["page1.html", "page2.html", "page3.html"];
    
        // Amount of time to spend on each page (in ms)
        var page_duration = 10000;
    
        var path = window.location.pathname;
        // handles the case where the path ends in "/"
        if (path.length == path.lastIndexOf('/')+1) {
            path = path.substr(0,path.length-1);
        }
        var last_page = paths[paths.length-1];
        var curr_page = path.substr(path.lastIndexOf('/')+1);
        var next_page = (curr_page == last_page) ? paths[0] : paths[paths.indexOf(curr_page)+1];
    
        setTimeout(function() {
            window.location.href = window.location.href.replace(curr_page, next_page);
        }, pageDuration);
    }
    

    想在你的问题中加些代码吗?可能会显示导航(我假设它包含所有要导航的页面)或提供一些关于页面名称的详细信息。这听起来很像网页的幻灯片,我会尝试调整现有的javascript幻灯片(在网上加载),并使其显示html而不是jpg,间隔后重定向将导致用户干预e.t.c出现问题,我猜页面加载时间也会出现问题
    function redirect() {
        window.location = "www.google.com";
    }
    
    setTimeout(redirect, 1000);
    
    window.onload = function() {
        // array of all the paths to the pages you have
        var paths = ["page1.html", "page2.html", "page3.html"];
    
        // Amount of time to spend on each page (in ms)
        var page_duration = 10000;
    
        var path = window.location.pathname;
        // handles the case where the path ends in "/"
        if (path.length == path.lastIndexOf('/')+1) {
            path = path.substr(0,path.length-1);
        }
        var last_page = paths[paths.length-1];
        var curr_page = path.substr(path.lastIndexOf('/')+1);
        var next_page = (curr_page == last_page) ? paths[0] : paths[paths.indexOf(curr_page)+1];
    
        setTimeout(function() {
            window.location.href = window.location.href.replace(curr_page, next_page);
        }, pageDuration);
    }