[英]javascript (greasemonkey) how to access a newly created iframe
我有这个网站,通过单击网站上的某些链接,将在同一窗口内创建iframe。
我的问题,只是想知道如何访问此iframe? 我尝试了document.getElementById()返回null尝试过的window.frames不存在
谢谢
如果为<iframe>
元素指定了ID,则document.getElementById()
将起作用。 如果您试图掌握其window
对象,则需要使用iframe元素的contentWindow
属性(或使用更标准的contentDocument
,它是对iframe document
对象的引用,但遗憾的是,IE至少没有此内容)直到并包括版本7):
var iframe = document.getElementById("your_iframe_id");
var iframeWin, iframeDoc;
if (iframe.contentDocument) {
iframeDoc = iframe.contentDocument;
iframeWin = iframeDoc.defaultView;
} else if (iframe.contentWindow) {
iframeWin = iframe.contentWindow;
iframeDoc = iframeWin.document;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.