[英]how to include html and js code into one single js file?
我需要包含一個iframe,該iframe必須具有響應能力,並且不能在多個網站中滾動。 我需要用一行這樣的代碼來做:
<script src="testfile.js"></script>
這是我必須以某種方式包含在testfile.js中的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>
</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響應並調整寬度
您不能在js中顯式使用HTML代碼,要編輯html標記的屬性,可以執行以下操作。 只需使用getElementsByTagName(“ iframe”)。style即可獲取HTML頁面中iframe的所有CSS參考,即可進行相應設置。
<!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";
}
如果可以,請在線程中響應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.