【发布时间】:2015-03-05 06:27:41
【问题描述】:
我想将 html 内容插入 iFrame。要求是我想在 iFrame 页面内容之前插入/附加此内容。
我有以下示例代码。目前我使用了 append 函数,它在 iframe 页面内容之后附加新内容。
TestPage.html
<html>
<head>
<script src="jquery.js"></script>
<title>Test Page</title>
</head>
<body>
<iframe id="sampleIframe" src="PopupPage.html" width="400" height="150"></iframe>
<script type="text/javascript">
$('#sampleIframe').load(function () {
var myFrame = $('#sampleIframe').contents().find('body');
myFrame.append('<div><h3>Hello, World</h3></div>');
})
</script>
</body>
</html>
PopupPage.html
<html>
<head>
<title>Popup Page</title>
</head>
<body>
You are on popup page.
</body>
</html>
【问题讨论】:
标签: javascript jquery html iframe