正则验证用户名和跨域postmessage

正则验证用户名

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form>
        <input type="text" pattern="[A-Za-z0-9]+" required title="用户名只能包含字母和数字">
        <input type="submit" value="提交">
      </form>
</body>
</html>

跨域postmessage

复制代码
##----------------------------class03----------------------------------------------------
#index.html
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2023</title>
</head>
    <div>
        <h1>www.test1.com</h1>
    </div>
</body>
<script>
    window.addEventListener('message', (event) => {
        if (event.origin === 'http://www.class2.cn') {
            const cookieData = event.data;
            //处理cookieData
            console.log('Receive message from parent:', cookieData);
            window.parent.postMessage('child message', '*');
        }
    })
</script>
 
</html>
 
#web.php
<?php 
$pets = $_POST['pet-select'];
echo $pets;?>
##----------------------------class04----------------------------------------------------
#child.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Child</title>
</head>
<body>
    <h1>child-html</h1>
</body>
<script>
    console.log(document.cookie);
    alert(1);
</script>
</html>
 
#index.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.test1.com/" frameborder="0"></iframe>
</body>
<script>
    window.onload = function() {
        document.cookie = 'sessionid=class2'
        const cookieData = document.cookie
        window.frames[0].postMessage(cookieData, 'http://www.test1.com/');
    }
    //添加一个监听事件处理子页面的返回消息
    window.addEventListener('message', (event) => {
        if(event.origin === 'http://www.test1.com')
        console.log('Received message from child:', event.data);
    })
</script>
</html>
相关推荐
青 春 记 忆7 分钟前
零基础入门Python11|Git实战:为任务管理器建立版本历史
开发语言·git·vscode·python·python3.11
To_OC13 分钟前
LC 239 滑动窗口最大值:从暴力超时到单调队列一遍过
javascript·算法·leetcode
Mh1 小时前
虚拟滚动真的比普通滚动性能更好吗?
前端·javascript·性能优化
余额瞒着我当琳2 小时前
C++--深拷贝三件套 + swap + 写时拷贝 + vector 扩容 + reserve
java·开发语言·c++
坐吃山猪2 小时前
WebClient内存配置解析
开发语言·springboot·webflux
jdksjw3 小时前
同步与异步、阻塞与非阻塞、多线程、协程超详细讲解(Python并发编程从入门到精通)
开发语言·python
Zach_菠萝侠3 小时前
【DeepSeek Harness 研究】进化方向4:安全加固 思考、设计与实现
开发语言·安全·deepseek
SL-staff4 小时前
技术实践:HR如何用JVS-Logic可视化编排实现考勤数据同步(含节点配置与异常处理)
开发语言·python·低代码·钉钉·可视化编排·jvs-logic·hr技术
kyriewen4 小时前
我把 AI 写的并发请求控制器手写了一遍——3 个语义我当时根本讲不清
前端·javascript·面试
SomeB1oody4 小时前
【RustyML入门】6.0. 数学工具
开发语言·后端·机器学习·rust·教程