javascript - How do I access different iframes? -


this question has answer here:

i working website uses different iframes on same webpage. wondering how can access , manipulate iframe not focused in on.

the website has body allows users type in, , want use method innerhtml (javascript) set value of text in box. however, i'm having trouble accessing iframe.

here javascript trying use, wasn't working intended.. getelementbyid not function of getelementsbytagname("iframe")

document.getelementsbytagname("iframe")[1].getelementbyid("tinymce").innerhtml="hello, world!" 

here 2 iframes working with: iframes cannot inspect page , change iframe hand, not answer looking for. thank clearing things me!

edit: suggested, try

document.getelementsbytagname("iframe")[1].document.getelementbyid("tinymce").innerhtml="hello, world!" 

however, still receiving uncaught type error

the outer html not have access iframe html. if intending change part of html iframe not correct solution.

however, pass parameter iframe src cause intended change.

eg.

if have iframe background needs changed based on action on outer html:

<iframe id="example" src="https://example.com?background="></iframe> 

you can change background blue changing src url parameter

document.getelementbyid('example').src = "https://example.com?background=blue"; 

and within iframe site html can parse query parameter , change background.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -