如何包含HTML和JS代码到一个单一的JS文件?

问题描述 投票:0回答:1

我需要包括一个iframe,是要响应,并在多个网站没有滚动。我需要做的是王氏的像这样的一行代码:

<script src="testfile.js"></script>

这是我的HTML代码以某种方式包括在testfile.js

<!doctype html>
<html class="no-js" lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Seamless.js | Beautiful, seamless iframes.</title>
  <script src="../build/seamless.parent.js"></script>
  <script type="text/javascript">
    window.onload = function() {
      window.seamless(document.getElementById('childpage'), {
        fallbackText: 'Having Trouble?'
      });
    };
  </script>
</head>
<body>
<div class="row panel">
  <div class="large-12 columns">
    <iframe id="childpage" src="example1.child.html?id=###"></iframe>
  </div>
</div>
</body>
</html>

我只能用iframe的一部分,以便有一行代码:

 <iframe id="childpage" src="example1.child.html?id=###"></iframe>

但我需要额外的HTML和JS,才能有iframe的响应,并与宽度可调

javascript html
1个回答
1
投票

不能使用HTML代码的JS里面明确,要编辑HTML标签,你可以做以下的特性。只要使用的getElementsByTagName(“IFRAME”)的风格来获取所有的I帧的CSS refrences在HTML页面中,你可以对其进行相应设置。

<!doctype html>
<html class="no-js" lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Seamless.js | Beautiful, seamless iframes.</title>
  <script src="../build/seamless.parent.js"></script>
   <script type="text/javascript">
    window.onload = function() {
      window.seamless(document.getElementById('childpage'), {
        fallbackText: 'Having Trouble?'
      });
    };
  </script>
  <script src="testfile.js"></script>
</head>
<body onload="myFunction()">
<div class="row panel">
  <div class="large-12 columns">
    <iframe id="childpage" src="example1.child.html?id=###"></iframe>
  </div>
</div>
</body>
</html>

testfile.js

function myFunction() {
  document.getElementsByTagName("iframe").style.overflow="hidden";
}

响应在线程,如果它的工作。

© www.soinside.com 2019 - 2024. All rights reserved.