test.html 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <!DOCTYPE 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>Document</title>
  7. <style>
  8. body {
  9. width: 100vw;
  10. height: 100vh;
  11. background: gray;
  12. }
  13. * {
  14. margin: 0;
  15. padding: 0;
  16. box-sizing: border-box;
  17. }
  18. iframe {
  19. position: absolute;
  20. bottom: 100px;
  21. right: 10px;
  22. z-index: 1000;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <iframe
  28. src="file:///D:/code/%E5%9B%9B%E7%BB%B4/%E9%B8%A6%E7%89%87%E6%88%98%E4%BA%89%E5%8D%9A%E7%89%A9%E9%A6%86/%E5%9C%BA%E6%99%AF/searchGuide/searchGuide.html"
  29. frameborder="0"
  30. id="myifr"
  31. width="10%"
  32. height="30%"
  33. ></iframe>
  34. <script>
  35. var iframe = document.getElementById("myifr");
  36. // iframe.width = iframe.contentWindow.document.body.scrollWidth;
  37. // iframe.height = iframe.contentWindow.document.body.scrollHeight;
  38. // console.log(iframe.contentWindow.document.body.scrollWidth);
  39. window.addEventListener("message", function (msg) {
  40. if (msg.data == "10") {
  41. iframe.width = "10%";
  42. } else if (msg.data == "26") {
  43. iframe.width = "26%";
  44. }
  45. console.log(msg.data, iframe.width);
  46. });
  47. </script>
  48. </body>
  49. </html>