javascript - 停止 IE/Edge 窗口调整为 iframe 尺寸

标签 javascript jquery html ajax iframe

问题: 通过 AJAX 调用将内容加载到 iframe 时,IE/Edge 会将浏览器窗口的大小调整为 iframe 的宽度和高度,而不是保持原始尺寸。 iframe 包含 <html><body>标签等等。

enter image description here

<iframe id="main" name="main" 
frameborder="0" width="100%" height="600" 
style="height: 600px !important; width: 100% !important;" 
scrolling="no" src="/en/courseid2900">
  #document
  <!DOCTYPE html>
  <html></html>
</iframe>

(在 IE/Edge 中进行 AJAX 调用之前)

enter image description here

<iframe id="main" name="main" 
frameborder="0" width="100%" height=""
style="height: 696.796875px"
scrolling="no" src="/en/courseid2900">
  #document
  <!DOCTYPE html>
  <html lang="en-US" class=" -webkit-">...</html>
</iframe>

(在 IE/Edge 中进行 AJAX 调用后)

那么,有没有办法如何阻止窗口大小调整到 iframe 尺寸?可以通过 jQuery 或 HTML hack 来完成吗?谢谢。

最佳答案

Iframe 元素 may not contain any content所以您在帖子中显示的代码是 100% 不正确的 HTML。如果您想要 iframe 中的内容,您可以使用 src 将其指向真实的 URL。属性,或者您在 JavaScript 中手动构造一个 iframe DOM 节点,然后将其插入到您的文档中。

根据 iframe 元素的定义,您作为标记而不是通过 JS 进行 DOM 操作而放入 iframe 元素内的任何内容都会被视为父文档内容。按照您的帖子的建议,您创建了一个包含两个的文档 <html>部分,浏览器会做一些非常不正确的事情并不奇怪:你做了一些非常不正确的事情=)

关于javascript - 停止 IE/Edge 窗口调整为 iframe 尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47823718/

相关文章:

javascript - 相对于鼠标位置定位 div

javascript - JSONObject.item 与 JSONObject ['item' ] 的相对处理速度是多少?

javascript - jQuery 文件上传库 : how to upload with a click for a SINGLE file

javascript - anythingslider navigationsize 不适用于首次加载 firefox 26

javascript - 如何在另一个文件的html上加载js Action

javascript - jQuery 对话框 : How do I alter the close tag style?

javascript - Canvas 通过 HTML 绘图并在屏幕调整大小时保留纵横比

javascript - 删除 Div 中的元素并循环直到元素存在 Javascript

javascript - 将 if 语句放入 javascript 标记内的 phtml 文件的有效方法

javascript - Googlebot 和 AngularJS 网站