【问题标题】:access external html body's width and height with javascript and/or jquery使用 javascript 和/或 jquery 访问外部 html 正文的宽度和高度
【发布时间】:2012-05-24 00:45:32
【问题描述】:

我正在使用fancybox 插件在fancybox 弹出窗口中打开一个html 文件。如何使用 javascript/jquery 访问外部 html 文件的宽度和高度。我的外部 html 看起来像这样:

<html>
<head>
<style type="text/css">
body {
  width:500px;
  height:500px;
  background-color:red;
}
</style>
</head>

<body>
<p>TEXT_TEXT_TEXT</p>
</body>
</html>

【问题讨论】:

  • FancyBox 是否在 iframe 中打开 html 文件?

标签: javascript jquery html external dimensions


【解决方案1】:

我猜 FancyBox 会在 iFrame 中加载 html 文件,那么它会是这样的:

这将转到您的 html 文件(在 iframe 中使用):

window.myFunction = function(width, height) {
 //change body width
 //change body height
}

这样您就可以在 iframe 中访问该功能

document.getElementById('YOURFRAMEIDHERE').contentWindow.myFunction(args);

【讨论】:

    猜你喜欢
    • 2012-05-29
    • 2011-03-11
    • 2013-12-24
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 2018-03-13
    • 2014-05-25
    • 1970-01-01
    相关资源
    最近更新 更多