Reputation: 278
I'm trying to change the element in one frames html with controls contained inside another frame. I can't however get it right to achieve this.
I basically have this:
<a href = "#" id = "c1" onclick = "document.getElementById('text').color = 'red'">red</a>
which is meant to change this.
<p id = "text">dsdsdsdsd</p>
I can't however figure out how to do this the right way.
Edit:
The main page for this looks as follows:
<frameset cols = "15%, *" frameborder="100" border="1" framespacing="1">
<frame src ="bookMenu.html" scrolling = "no"/>
<frameset rows = "*, 10%" frameborder="100" border="1" framespacing="1">
<frame src ="book1_intro.html" scrolling= "yes" name = "main"/>
<frame src ="book_controls.html" scrolling= "no" name = "control"/>
</frameset>
The Calling button is in the framed named control and the destination is in the frame named main
Upvotes: 1
Views: 9334
Reputation: 23416
If you really have frame
s, set a name
attribute for the frame
elements in frameset
(s). Then you can refer to the #text
from any frame (or frameset
document) like this:
var text = top.window.main.document.getElementById('text');
Notice, that if this is a local page, you can't refer (i)frame
s, when using Chrome. However, there's a workaround for this: add --allow-file-access-from-files
to the target path of the Chrome icon, and open Chrome by clicking this modified icon before opening the frameset file.
Upvotes: 1
Reputation: 7636
You need to get a reference to the parent first, then a reference to the frame that contains your paragraph tag and use contentDocument to get at the document within that frame.
See:
How to access parent Iframe from javascript
How can I access iframe elements with Javascript?
Upvotes: 1