首页 > 其他分享 >外链跳转到中间页

外链跳转到中间页

时间:2024-07-25 14:07:15浏览次数:10  
标签:tiaozhuan target element 中间 href && 跳转 外链

20240303104439913

前言

网络安全的问题这些年越来越被关注,所以各大平台网站例如微博、微信、QQ、网易等,都在这几年为自家的网络产品添加了一个安全跳转的中台页面,甚至微博对于跳转链接必须是企业认证才能进入微博的安全白名单,可以说是把安全做到了极致

加了安全跳转中台以后,这样可以让自己的产品主域名成功与外链间接通过中台串联,而不是直接关系,增加安全跳转中台页面也间接提升了网络产品的用户体验。

操作

新建 js 文件,如:safe.js。里面的网址为排除跳转中间页。

function checkParent(element, classNames) {
    while (element) {
        if (element.classList && classNames.some(cn => element.classList.contains(cn))) {
            return true;
        }
        element = element.parentElement;
    }
    return false;
}
var excludedClasses = ['card-link', 'friend-item', 'contact-item', 'footer-item']; // 添加需要排除的a标签类名class
window.addEventListener('load', (event) => {
    document.body.addEventListener('click', function(e) {
        let target = e.target;
        while (target && target.nodeName !== 'A') {
            target = target.parentNode;
        }
        if (target && target.nodeName === 'A' &&
            !checkParent(target, excludedClasses) &&
            !target.href.includes('gorpeln.top') &&
            !target.href.includes('gorpeln.eu.org') &&
            !target.href.includes('lab.gorpeln.top') &&
            !target.href.includes('github.com') &&
            target.hostname !== window.location.hostname) {
            e.preventDefault();
            let encodedUrl = btoa(target.href); // Base64 encode the URL
            let url = '/go-wild?target=' + encodedUrl;
            window.open(url, '_blank');
        }
    });
});

新建一个 html,如go-wild.html

<div class="tiaozhuan-all">
    <div class="tiaozhuan-nrong">
        <div class="tiaozhuan-title">即将离开 『 gorpeln's Blog 』 ,跳转到以下外部链接</div>
        <div id="tiaozhuan-link"></div>
        <div class="tiaozhuan-info">请自行识别该链接是否安全,并保管好个人信息。</div>
        <div class="tiaozhuan-button"><a href='' id='direct-link'>继续访问</a></div>
    </div>
</div>
<script>
    const params = new URLSearchParams(window.location.search);
    const encodedTarget = params.get('target');
    const target = atob(encodedTarget); // 使用 atob 进行 Base64 解码

    if (target) {
        document.getElementById('direct-link').href = target;
        document.getElementById('tiaozhuan-link').textContent = '' + target; // 直接显示目标地址    
    } else {
        console.error('未指定重定向目标。');
    }
</script>

相关 css,根据主题风格调整。

body {
    background: #ececec;
}

.tiaozhuan-all {
    position: relative;
    box-shadow: rgba(0, 0, 0, 0.25) 0px 25px 50px -10px;
    border-radius: 10px;
    background: #fff url(../assets/img/go-wild.png) no-repeat center center / cover;
    color: #666;
    word-break: break-all;
    max-width: 700px;
    height: 350px;
    text-align: center;
    font-size: 0.85rem;
    overflow: hidden;
    margin: 100px auto 0;

    @include breakpoint('small') {
        aspect-ratio: 2 / 1;
        height: auto;
    }
}

.tiaozhuan-nrong {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px 20px 30px 20px;
}

.tiaozhuan-title {
    font-size: 1.3rem;
    color: #222;
    line-height: 1.4;
    margin-bottom: 4px;
}

.tiaozhuan-info {
    margin-top: 6px;
}

.tiaozhuan-button {
    margin-top: 20px;
}

.tiaozhuan-button a {
    color: #fc9151;
    border-radius: 4px;
    padding: 10px 30px;
    font-size: .85rem;
    border: 0.5px solid #fc9151;
    display: inline-block;
    text-decoration: none;

}

最后在页尾引用js文件即可,如

<script src="/js/safe.js"></script>

思路

js文件识别链接的a标签,并把链接用 base64 编码,同时排除一些不需要跳转中间页的class或网站。然后跳转到go-wild.html文件中(链接格式为/go-wild?target=base64编码),html文件承担了中间页具体信息,及跳转动作。如使用base64解码跳转的链接。

结语

对于浏览体验来说,多了一步跳转,总归是不好,但为了愉快的玩耍博客,稳妥一点更佳。如果觉得跳转中间页很烦人,浏览器可以装个 Skip Redirect 插件,告别所有网站的中间页跳转,直接抵达目标地址。

{% include reference.html links=page.reference_links %}

标签:tiaozhuan,target,element,中间,href,&&,跳转,外链
From: https://www.cnblogs.com/gorpeln/p/18322884

相关文章

  • 每日一面—— 不使用任何中间变量如何将a、b的值进行交换
    请参考以下C++程序代码。1#include<stdio.h>23voidswap1(int&a,int&b)4{5inttemp=a;//使用局部变量temp完成交换6a=b;7b=temp;8};910voidswap2(int&a,int&b)11{12a=a+b;//使用加减运算完成交换13b=a-b;14......
  • JS劫持、DNS劫持与页面劫持跳转详解
    网络安全威胁种类繁多,其中JS劫持、DNS劫持和页面劫持跳转是常见的攻击手段。本文将详细讲解这些攻击的原理、方法和防御措施,帮助你更好地保护你的网络环境。一、JS劫持1.什么是JS劫持?JS劫持(JavaScriptHijacking)是一种通过恶意JavaScript代码控制或篡改网页内容的攻击手段......
  • 抖音私信卡片制作教程,使用W外链创建抖音/快手/小红书卡片
    在数字营销和社交媒体日益繁荣的今天,利用外部链接(W外链平台)为抖音平台创建卡片已成为一种有效的推广手段。抖音卡片不仅可以直接将观众导向目标网页或产品,还能提高用户的参与度和品牌的曝光度。下面,我们将详细介绍如何使用W外链平台创建抖音卡片。 一、了解W外链平台和抖音卡......
  • 使用 matplotlib 在中间设置 xtick 标签
    我有以下一段随机代码,它只是使用一些随机数绘制散点图。importmatplotlib.pyplotaspltimportmatplotlib.tickerastickerimportnumpyasnpx=np.random.rand(10)y=np.random.rand(10)fig,ax=plt.subplots()ax.plot(y,x,'*')plt.show()它会生成这样......
  • MiniAuth 一个轻量 ASP.NET Core Identity Web 后台管理中间插件
    MiniAuth一个轻量ASP.NETCoreIdentityWeb后台管理中间插件「一行代码」为「新、旧项目」添加Identity系统跟用户、权限管理网页后台系统开箱即用,避免打掉重写或是严重耦合情况Github:https://github.com/mini-software/MiniAuth,Gitee:https://gitee.com/shps9510......
  • 微服务常用的中间件有哪些?都有什么用途?
    前言最近整理一下我们的项目使用了哪些中间件,借此机会也来分享一下,在微服务架构中我们常用的那些中间件,都有什么作用,为什么要使用中间件。消息中间件-RocketMQ比如RocketMQ,RocketMQ是一个开源的分布式消息传递和流处理平台,由阿里巴巴开发并贡献给Apache软件基金会。它被......
  • 深入理解Django:中间件与信号处理的艺术
    引言在当今的Web开发领域,Django以其强大的功能、简洁的代码结构和高度的可扩展性,已成为众多开发者的首选框架。Django不仅是一个内容管理系统,更是一个全面的框架,它提供了一套完整的解决方案,包括ORM、模板引擎、URL路由系统和强大的管理后台,使得开发者能够快速构建高质量的Web......
  • 3. 中间件的最佳方法
    中间件是ASP.NETCore中最强大的概念之一。对于传统的ASP.NET开发人员来说,“中间件”是一个相对较新的术语。在中间件出现之前,存在HTTP处理程序和模块,需要通过web.config进行单独的代码配置。现在,中间件被视为ASP.NET应用程序中的一等公民,使其更易于在单个代码库......
  • 集群及分布式定时任务中间件MEE_TIMED
    集群及分布式定时任务中间件MEE_TIMED转载请著名出处:https://www.cnblogs.com/funnyzpc/p/18312521MEE_TIMED一套开源的定时任务中间件,MEE_TIMED简化了scheduled及shedlock的配置,同时也升级了这两种中间件的能力,使定时任务开发更具灵活性的同时具备集群及分布式节点的管理......
  • [email protected](62)[email protected](11)- 中间件2 - redux-thunk
    目录1,介绍举例2,原理和实现实现3,注意点1,介绍一般情况下,action是一个平面对象,并会通过纯函数来创建。exportconstcreateAddUserAction=(user)=>({type:ADD_USER,payload:user,});这样是有一些限制的无法使用异步的,比如在请求接口之后再做一......