重定向网页

使用油猴(Tampermonkey)插件来添加一个JavaScript脚本。这个脚本将会监听特定的URL,并在用户访问该URL时将其重定向到一个新的URL。

以下是实现这个功能的JavaScript脚本的一个例子:

// ==UserScript==
// @name         Redirect Script
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://192.168.1.254:8000/portal/local/index.html?weburl=http%3A%2F%2Fwww.msftconnecttest.com%2Fredirect
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 监听页面加载完成事件
    window.addEventListener('load', function() {
        // 获取当前URL
        var currentURL = window.location.href;

        // 检查当前URL是否匹配目标URL
        if (currentURL.indexOf('http://192.168.1.254:8000/portal/local/index.html?weburl=http%3A%2F%2Fwww.msftconnecttest.com%2Fredirect') !== -1) {
            // 重定向到新的URL
            window.location.href = 'http://192.168.1.254:8000/portal/local/index.html';
        }
    });
})();

 

posted @ 2024-07-04 11:16  MING5135  阅读(7)  评论(0编辑  收藏  举报