如何跳出frameset。

本文介绍了在使用frameset布局的网页中实现登出功能的方法,通过JavaScript判断当前窗口是否为顶级窗口并进行重定向,同时提供了直接登出时设置href属性target='_top'的建议。
<html>
<head>


</head>
<body>
<script type="text/javascript">
if (window.top!=window.self){
	window.top.location="index.htm";
}
</script>
</body>
</html>

在frameset的页面中登出,往往会被frame在框架内,那么重定向到这个页面就可以了。
如果是直接登出,herf中有个属性叫做target="_top"


// 非法字符检测正则表达式 const illegalPatterns = [ /<(script|iframe|object|embed|link|style|meta|frame|frameset|applet|form)\b[^>]*>/gi, /<\/(script|iframe|object|embed|link|style|meta|frame|frameset|applet|form)\s*>/gi, /\s(on\w+)\s*=\s*["'][^"']*["']/gi, /\s(srcdoc)\s*=\s*["'][^"']*["']/gi, /\s(href|src)\s*=\s*["']javascript:[^"']*["']/gi, /\s(href|src)\s*=\s*["']vbscript:[^"']*["']/gi, /\s(href|src)\s*=\s*["']data:(?!image\/)[^;]*;base64,[^"']*["']/gi, /\s(style)\s*=\s*["'][^"']*(expression|javascript:)[^"']*["']/gi ]; // 检查输入是否包含非法字符 function containsIllegalChars(input) { if (!input || typeof input !== 'string') return false; for (let pattern of illegalPatterns) { if (pattern.test(input)) { return true; } } return false; } // 移除危险标签和属性 function removeDangerousContent(input) { if (!input || typeof input !== 'string') return input; let cleanedInput = input; // 移除危险标签 for (let pattern of illegalPatterns) { cleanedInput = cleanedInput.replace(pattern, ''); } return cleanedInput; } // 移除残缺的HTML标签和属性 function removeIncompleteHtml(input) { if (!input || typeof input !== 'string') return input; let result = input; // 移除残缺的闭合标签(如 </div 但没有 >) result = result.replace(/<\/[^>]*$/g, ''); // 移除残缺的开放标签(如 <div 但没有 >) result = result.replace(/<[^>]*$/g, ''); // 移除残缺的属性(如 onclick="alert(1) 但没有闭合引号) result = result.replace(/\s\w+\s*=\s*["'][^"']*$/g, ''); // 移除孤立的引号 result = result.replace(/["']$/g, ''); // 移除多余的 > 字符 result = result.replace(/^>+/, ''); // 开头的 > 字符 result = result.replace(/>+$/, ''); // 结尾的 > 字符 return result; } // 综合清理函数 function cleanInputContent(input) { if (!input || typeof input !== 'string') return input; // 第一步:移除危险内容 let cleaned = removeDangerousContent(input); // 第二步:移除残缺HTML结构 cleaned = removeIncompleteHtml(cleaned); // 第三步:再次清理确保没有遗漏 cleaned = removeIncompleteHtml(cleaned); return cleaned; } // 处理非法字符输入(先清除再提示) let alertShown = {}; // 用于跟踪已经显示过提示的元素 function handleIllegalInput(element) { // 先移除危险内容,而不是清空整个输入 const cleanedValue = cleanInputContent(element.value); if (element.value !== cleanedValue) { element.value = cleanedValue; } // 为每个元素创建唯一的标识 const elementId = element.id || element.name || (element.tagName + Math.random()); // 如果还没有为这个元素显示过提示,则显示提示 if (!alertShown[elementId]) { alertShown[elementId] = true; layer.alert("检测到非法字符,已自动移除", { title: '输入提示', icon: 1, end: function() { // 提示关闭后,允许再次显示提示 alertShown[elementId] = false; } }); } } // 非法字符检测函数 function checkIllegalChars(element) { if (containsIllegalChars(element.value)) { handleIllegalInput(element); return false; } return true; } // 检查所有输入框是否有非法字符(用于提交前检查) function checkAllInputsForIllegalChars() { // 获取当前页面所有文本输入框 const inputElements = document.querySelectorAll( 'input[type="text"], input[type="search"], input[type="tel"], ' + 'input[type="email"], input[type="url"], textarea' ); for (let element of inputElements) { if (containsIllegalChars(element.value)) { // 聚焦到有问题的输入框 element.focus(); // 提示用户 handleIllegalInput(element); return false; // 发现非法字符,返回false } } return true; // 所有输入框都通过检查 } // 为指定的输入框添加非法字符检测 function addIllegalCharCheck(element) { // 键盘按下时检查 element.addEventListener('keydown', function(e) { // 使用setTimeout确保在字符输入后进行检查 setTimeout(() => { checkIllegalChars(this); }, 0); }); // 失去焦点时再次检查(双重保险) element.addEventListener('blur', function() { // 在blur时进行更彻底的清理 const cleanedValue = cleanInputContent(this.value); if (this.value !== cleanedValue) { this.value = cleanedValue; } if (containsIllegalChars(cleanedValue)) { handleIllegalInput(this); } }); // 粘贴时检查 element.addEventListener('paste', function() { // 稍微延迟检查,确保粘贴内容已经生效 setTimeout(() => checkIllegalChars(this), 10); }); } // 初始化所有需要非法字符检测的输入框 function initIllegalCharCheck() { // 获取当前页面所有文本输入框 const inputElements = document.querySelectorAll( 'input[type="text"], input[type="search"], input[type="tel"], ' + 'input[type="email"], input[type="url"], textarea' ); // 为每个输入框添加检测 inputElements.forEach(element => { addIllegalCharCheck(element); }); } // 页面加载完成后初始化 document.addEventListener('DOMContentLoaded', function() { initIllegalCharCheck(); }); // 暴露公共方法供外部调用 window.XssFilter = { init: initIllegalCharCheck, checkAll: checkAllInputsForIllegalChars, checkElement: checkIllegalChars, cleanInputContent: cleanInputContent, removeDangerousContent: removeDangerousContent }; 现在有一些问题:<div><iframe srcdoc='<script>alert(1)</script>'></处理成了这样<div>alert(1),能不能去掉多余的单标签清理以下
最新发布
08-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值