用javascript / html控制iframe内容 [英] Control iframe content with javascript/html

查看:65
本文介绍了用javascript / html控制iframe内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网页中,我有一个如下的iframe:

Within my webpage I have an iframe like so:

<iframe src="thispage.html" width="100%" height="600" frameBorder="2"></iframe>

(iframe是同一网站上的一个页面...)

(The iframe is of a page on the same site...)

我的问题是,是否有可能在具有iframe的页面上使用javascript来控制'thispage.html'(如使用javascript函数?)

My question is, is it possible to use javascript on the page that has the iframe to control the 'thispage.html' (like use javascript functions?)

推荐答案

是的,你可以。然后说你的iframeId是myIframe;

Yes you can. Say your iframeId is myIframe then;

<iframe id="myIframe" 
        src="thispage.html" width="100%" height="600" frameBorder="2"></iframe>

JavaScript:

JavaScript:

//get the iframe
var iframe = document.getElementById("myIframe");

//For ex; say you have a button called mybutton in thispage.html page
//you can access it as follows.
var btn = iframe.contentWindow.document.getElementById('mybutton');

//if you need to call a function
iframe.contentWindow.yourFunction();

这篇关于用javascript / html控制iframe内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆