在我的网页中,我有一个像这样的 iframe:
<iframe src="thispage.html" width="100%" height="600" frameBorder="2"></iframe>
(iframe 是同一网站上的页面......)
我的问题是,是否可以在具有 iframe 的页面上使用 javascript 来控制“thispage.html”(例如使用 javascript 函数?)
是的你可以。说出你的iframe
的 ID 是'myIFrame'
<iframe id="myIFrame" src="thispage.html"
width="100%" height="600"
frameBorder="2">
</iframe>
然后,在 JavaScript 中添加以下内容:
// Get the iframe
const iFrame = document.getElementById('myIFrame');
// Let's say that you want to access a button with the ID `'myButton'`,
// you can access via the following code:
const buttonInIFrame = iFrame.contentWindow.document.getElementById('myButton');
// If you need to call a function in the iframe, you can call it as follows:
iFrame.contentWindow.yourFunction();
希望能帮助到你 :)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)