• 正则验证用户名和跨域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>Documenttitle>
    7. head>
    8. <body>
    9. <form>
    10. <input type="text" pattern="[A-Za-z0-9]+" required title="用户名只能包含字母和数字">
    11. <input type="submit" value="提交">
    12. form>
    13. body>
    14. html>

    二、跨域postmessage 

    1. ##----------------------------class03----------------------------------------------------
    2. #index.html
    3. html>
    4. <html lang="en">
    5. <head>
    6. <meta charset="UTF-8">
    7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    8. <title>2023title>
    9. head>
    10. <div>
    11. <h1>www.test1.comh1>
    12. div>
    13. body>
    14. <script>
    15. window.addEventListener('message', (event) => {
    16. if (event.origin === 'http://www.class2.cn') {
    17. const cookieData = event.data;
    18. //处理cookieData
    19. console.log('Receive message from parent:', cookieData);
    20. window.parent.postMessage('child message', '*');
    21. }
    22. })
    23. script>
    24. html>
    25. #web.php
    26. $pets = $_POST['pet-select'];
    27. echo $pets;?>
    28. ##----------------------------class04----------------------------------------------------
    29. #child.html
    30. html>
    31. <html lang="en">
    32. <head>
    33. <meta charset="UTF-8">
    34. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    35. <title>Childtitle>
    36. head>
    37. <body>
    38. <h1>child-htmlh1>
    39. body>
    40. <script>
    41. console.log(document.cookie);
    42. alert(1);
    43. script>
    44. html>
    45. #index.html
    46. html>
    47. <html lang="en">
    48. <head>
    49. <meta charset="UTF-8">
    50. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    51. <title>iframetitle>
    52. head>
    53. <body>
    54. <iframe id="myIframe" src="http://www.test1.com/" frameborder="0">iframe>
    55. body>
    56. <script>
    57. window.onload = function() {
    58. document.cookie = 'sessionid=class2'
    59. const cookieData = document.cookie
    60. window.frames[0].postMessage(cookieData, 'http://www.test1.com/');
    61. }
    62. //添加一个监听事件处理子页面的返回消息
    63. window.addEventListener('message', (event) => {
    64. if(event.origin === 'http://www.test1.com')
    65. console.log('Received message from child:', event.data);
    66. })
    67. script>
    68. html>

  • 相关阅读:
    C语言时间函数gmtime和localtime
    spring总结
    2.6 动态规划—lc炒股系列
    一些可以参考的文档集合6
    16. Java字符串拼接的低层原理
    【HCIA-cloud】【1】云计算的定义、什么是云计算、云计算的架构与技术说明、华为云计算产品、华为内存DDR配置工具说明
    GitOps 工具 Argo CD 实战教程
    如何提高一个网站的排名?
    海外问卷调查是不是很枯燥?
    神经网络-卷积神经网络案例详解
  • 原文地址:https://blog.csdn.net/m0_64449718/article/details/133677326