• 正则验证用户名和跨域postmessage


    正则验证用户名

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>登录title>
    6. head>
    7. <body>
    8. <input type="text" name="username" placeholder="用户名" id="username" onchange="validateUsername()">
    9. <input type="submit" value="登录">
    10. <script>
    11. function validateUsername() {
    12. var username = document.querySelector("#username").value;
    13. // 使用正则表达式验证用户名
    14. var reg = /^[a-zA-Z]+$/;
    15. if (!reg.test(username)) {
    16. alert("用户名必须是纯字母!");
    17. document.querySelector("#username").value = "";
    18. }
    19. }
    20. script>
    21. body>
    22. html>

    跨域postmessage  

    配置好虚拟主机

    对两个网站分别进行以下配置

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <title>2023title>
    7. head>
    8. <body>
    9. <div>
    10. <h1>www.fjq.comh1>
    11. div>
    12. body>
    13. <script>
    14. window.addEventListener('message', (event) => {
    15. if (event.origin === 'http://www.fjq.com') {
    16. const cookieData = event.data;
    17. //处理cookieData
    18. console.log('Receive message from parent:', cookieData);
    19. window.parent.postMessage('child message', '*');
    20. }
    21. })
    22. script>
    23. html>
    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <title>iframetitle>
    7. head>
    8. <body>
    9. <iframe id="myIframe" src="http://www.fjq.com/" frameborder="0">iframe>
    10. body>
    11. <script>
    12. window.onload = function() {
    13. document.cookie = 'sessionid=example'
    14. const cookieData = document.cookie
    15. window.frames[0].postMessage(cookieData, 'http://www.fjq.com/');
    16. }
    17. //添加一个监听事件处理子页面的返回消息
    18. window.addEventListener('message', (event) => {
    19. if(event.origin === 'http://www.fjq.com')
    20. console.log('Received message from child:', event.data);
    21. })
    22. script>
    23. html>

     

  • 相关阅读:
    kubeadm搭建k8s集群1.25版本完整教程【doker、网络插件calico、中间层cri-docker】
    json提取-响应报文中是json数组
    网络-网络状态&网络速度
    ATF lds和代码section如何关联
    PyQt5的安装和配置
    YOLO V7源码解析
    奇虎360Java笔试题
    代理IP与Socks5代理在网络安全与数据隐私中的关键作用
    npm排错记录
    51-60==c++知识点
  • 原文地址:https://blog.csdn.net/weixin_63781898/article/details/133685269