最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript - how to change elements content inside a page when using iframes, using dom, not jquery - Stack Overflow

programmeradmin3浏览0评论

I have this iframe and as u can see it call a js function with the onload trigger.

<iframe name="top" id="top" width="99%" height="20%" src="top.htm" frameborder="0" scrolling="no" onload="log_in()"></iframe>

What i need to do is to effect the element inside "top.htm" (change innerHTML and stuff like that) from that function.

But the problem is that the funnction does not recognize the elements of the "top.htm" page, only the ones in index.htm (the page with the iframes).

p.s. i have to use DOM and i have to use iframes.

Any one knows how to do that?

10x :-)

I have this iframe and as u can see it call a js function with the onload trigger.

<iframe name="top" id="top" width="99%" height="20%" src="top.htm" frameborder="0" scrolling="no" onload="log_in()"></iframe>

What i need to do is to effect the element inside "top.htm" (change innerHTML and stuff like that) from that function.

But the problem is that the funnction does not recognize the elements of the "top.htm" page, only the ones in index.htm (the page with the iframes).

p.s. i have to use DOM and i have to use iframes.

Any one knows how to do that?

10x :-)

Share Improve this question asked May 19, 2010 at 17:52 ErezErez 1,9535 gold badges29 silver badges59 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

For example access to all dom elements:

document.getElementById("top").contentWindow.document.getElementsByTagName("*")

Is it your problem?

The Iframe Window and its Document

References to the window generated by the iframe and to the document loaded into the iframe can be obtained via the frames array using the name attribute.

window.frames[iframeName]
window.frames[iframeName].document

The frames array method of referencing has broad support, even among quite old browsers, as long as you attach a name attribute to the iframe. For best results, use both name and id.

For more up-to-date browsers, the document inside the iframe can also be referenced via contentWindow (IE win) and contentDocument (DOM) properties of the iframe element:

// IE5.5+ windows
document.getElementById(iframeId).contentWindow
document.getElementById(iframeId).contentWindow.document

or,

// DOM 
document.getElementById(iframeId).contentDocument

from http://www.dyn-web./tutorials/iframes/

sample here: http://www.dyn-web./tutorials/iframes/refs.php

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论