test.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. if (window.innerWidth < 700) {
  40. iframe.height = 20 + "%";
  41. iframe.width = 20 + "%";
  42. }
  43. window.addEventListener("message", function (msg) {
  44. if (msg.data.params.num) {
  45. iframe.width = msg.data.params.num + "%";
  46. }
  47. });
  48. </script>
  49. </body>
  50. </html>