正则验证用户名和跨域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>
相关推荐
zttbee4 小时前
echarts图表tooltip色块失效
前端·javascript·echarts
H.莓飛4 小时前
【数据结构】排序_OJ题(一):计数、桶与排序后的处理
java·开发语言·数据结构
wangchunyu1145 小时前
JAVA AQS与Lock实现原理(含CAS)
java·开发语言·word
虚无境6 小时前
如何用AI帮我写出实用的插件
前端·javascript·ai编程
爱喝水的鱼丶6 小时前
SAP-ABAP:ECC→S/4HANA ABAP 迁移升级指南——程序改造、语法兼容与性能优化 导语
运维·开发语言·性能优化·sap·abap·经验交流·开发交流
小灰灰搞电子6 小时前
Rust+Slint 实现FTP客户端调试助手源码分享
开发语言·后端·rust
外收内放6 小时前
面向对象高级(实战案例)
开发语言·python·学习
zimoyin7 小时前
在 C# 里嵌入 JavaScript:用 Jint 做可热更新的自动化脚本(从入门到踩坑)
javascript·c#·自动化
fanruitian7 小时前
python else用法
开发语言·python
FRing038 小时前
JavaScript入门到精通二十六(变量提升、函数剩余参数、展开运算符、ES6箭头函数)
开发语言·前端·javascript·es6·箭头函数