正则验证用户名和跨域postmessage

正则验证用户名

跨域postmessage

要用到俩个虚拟机:

html 复制代码
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>10.1</title>
</head>
 
<body>
    <div>
        <h1>www.s1mple.com</h1>
    </div>
</body>
<script>
    window.addEventListener('message', (event) => {
        if (event.origin === 'http://www.s1mple1.com') {
            const cookieData = event.data;
            //处理cookieData
            console.log('Receive message from parent:', cookieData);
            window.parent.postMessage('child message', '*');
        }
    })
</script>
</html>
html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>iframe</title>
</head>
<body>
    <iframe id="myIframe" src="http://www.s1mple.com/" frameborder="0"></iframe>
</body>
<script>
    window.onload = function() {
        document.cookie = 'sessionid=example'
        const cookieData = document.cookie
        window.frames[0].postMessage(cookieData, 'http://www.s1mple.com/');
    }
    //添加一个监听事件处理子页面的返回消息
    window.addEventListener('message', (event) => {
        if(event.origin === 'http://www.s1mple.com')
        console.log('Received message from child:', event.data);
    })
</script>
</html>

相关推荐
北冥有一鲲7 分钟前
LangChain.js:Tool、Memory 与 Agent 的深度解析与实战
开发语言·javascript·langchain
吴佳浩 Alben16 分钟前
Python入门指南(六) - 搭建你的第一个YOLO检测API
开发语言·python·yolo
love530love17 分钟前
Win11+RTX3090 亲测 · ComfyUI Hunyuan3D 全程实录 ③:diso 源码编译实战(CUDA 13.1 零降级)
开发语言·人工智能·windows·python·comfyui·hunyuan3d·diso
qq_3771123717 分钟前
JAVA的平凡之路——此峰乃是最高峰JVM-GC垃圾回收器(2)-06
java·开发语言·jvm
霁月的小屋19 分钟前
Vue响应式数据全解析:从Vue2到Vue3,ref与reactive的实战指南
前端·javascript·vue.js
weixin_4686352921 分钟前
用python获取双色球历史数据,纯数据处理,非爬虫
开发语言·爬虫·python
李少兄24 分钟前
深入理解 Java Web 开发中的 HttpServletRequest 与 HttpServletResponse
java·开发语言·前端
kylezhao201929 分钟前
C#变量 + 工业常用数据类型:重点 byte/int/float
开发语言·c#·c#上位机
yyy(十一月限定版)33 分钟前
c语言——二叉树
c语言·开发语言·数据结构
froginwe1137 分钟前
Web 品质国际化
开发语言