您好,欢迎来到95分类目录!
当前位置:95分类目录 » 站长资讯 » 站长教程 » 35dir专区 » 文章详细 订阅RssFeed

35dir前后端提交网站时粘贴的链接自动去掉https(http)://

来源:本站原创 浏览:23次 时间:2025-03-03
简介:前端添加 进入/themes/default目录找到website.html,在最底部的{#include file="footer.html"#}上面加入以下代码         // DOM加载完成后执行         document.addEventListener('DOMContentLoaded', function() {             const urlI

前端添加

进入/themes/default目录找到website.html,在最底部的{#include file="footer.html"#}上面加入以下代码


<script>
        // DOM加载完成后执行
        document.addEventListener('DOMContentLoaded', function() {
            const urlInput = document.getElementById('web_url');
            
            // 实时输入处理
            urlInput.addEventListener('input', function(e) {
                this.value = sanitizeURL(this.value);
            });


            // 失焦时最终校验
            urlInput.addEventListener('blur', function(e) {
                this.value = finalCheckURL(this.value);
            });
        });


        // 即时清理函数
        function sanitizeURL(url) {
            return url
                .replace(/^s+/, '')         // 去除首部空格
                .replace(/^(https?|ftp):///i,'')  // 移除协议头
                .replace(/^/+/g, '')        // 移除开头的斜杠
                .replace(/s+/g, '')         // 移除所有空格
                .replace(//+/g, '/');       // 合并多余斜杠
        }


        // 最终校验函数
        function finalCheckURL(url) {
            const cleaned = sanitizeURL(url)
                .replace(//+$/g, '')        // 去除末尾斜杠
                .trim();
            
            // 添加自定义校验逻辑(示例)
            if (!cleaned) {
                console.warn('URL不能为空');
            }
            
            return cleaned;
        }
    </script>


后端添加

进入/themes/system目录找到website.html,在最底部的{#include file="footer.html"#}上面加入以下代码

<script>
        // DOM加载完成后执行
        document.addEventListener('DOMContentLoaded', function() {
            const urlInput = document.getElementById('web_url');
            
            // 实时输入处理
            urlInput.addEventListener('input', function(e) {
                this.value = sanitizeURL(this.value);
            });


            // 失焦时最终校验
            urlInput.addEventListener('blur', function(e) {
                this.value = finalCheckURL(this.value);
            });
        });


        // 即时清理函数
        function sanitizeURL(url) {
            return url
                .replace(/^s+/, '')         // 去除首部空格
                .replace(/^(https?|ftp):///i,'')  // 移除协议头
                .replace(/^/+/g, '')        // 移除开头的斜杠
                .replace(/s+/g, '')         // 移除所有空格
                .replace(//+/g, '/');       // 合并多余斜杠
        }


        // 最终校验函数
        function finalCheckURL(url) {
            const cleaned = sanitizeURL(url)
                .replace(//+$/g, '')        // 去除末尾斜杠
                .trim();
            
            // 添加自定义校验逻辑(示例)
            if (!cleaned) {
                console.warn('URL不能为空');
            }
            
            return cleaned;
        }
    </script>

© 版权声明