正则验证用户名和跨域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>
相关推荐
Icoolkj31 分钟前
VuePress 与 VitePress 深度对比:特性、差异与选型指南
前端·javascript·vue.js
honder试试2 小时前
焊接自动化测试平台图像处理分析-模型训练推理
开发语言·python
^Rocky2 小时前
JavaScript性能优化实战
开发语言·javascript·性能优化
ponnylv2 小时前
深入剖析Spring Boot启动流程
java·开发语言·spring boot·spring
萧邀人2 小时前
第一课、Cocos Creator 3.8 安装与配置
开发语言
西陵2 小时前
Nx带来极致的前端开发体验——任务编排
前端·javascript·架构
笑鸿的学习笔记2 小时前
JavaScript笔记之JS 和 HTML5 的关系
javascript·笔记·html5
Jayden_Ruan3 小时前
C++逆向输出一个字符串(三)
开发语言·c++·算法
不吃鱼的羊3 小时前
启动文件Startup_vle.c
c语言·开发语言
VBA63373 小时前
VBA之Word应用第四章第二节:段落集合Paragraphs对象(二)
开发语言