0

I am trying to get the data that sits inside <p id="wysiwygBody"></p> within an Iframe...

I have a wysiwyg editor that generates an Iframe for users to type rich content into. When I type into the wysiwyg Iframe I wish to capture what has been typed into a seperate hidden form field on the parent page onmouseover.

UPDATE: --------------------------------------------------------------------

I've added an id to the Iframe called: wysiwygFrame and also added an id to the Iframes only P element called: wysiwygBody.

I am now accessing the Iframe as suggested with id's like so:

var messageContent = window.frames['wysiwygFrame'].document.getElementById('wysiwygBody').value;

and attempting to update the value of a form field called CurrentDraftMessage like so:

document.getElementById('CurrentDraftMessage').value = messageContent; 

It doesn't work at all???

1 Answer 1

2

accessing an element in a IFrame should be done like this:

window.frames['iFrameName'].document.getElementById('elementId').value = v;
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for so much for such a fast response... One of the issues is that the wysiwyg has no id for it's Iframe and although I tried to add one in via the wysiwyg's js files it seems to ignore any id being set. so I had to access it via document.getElementsByTagName('iframe')[0]; also the wysiwyg's body container also has no id and is simply stored inside of <p></p> which I had to access via getElementsByTagName('p')[0].innerHTML; any advice?
every/any DOM element may have an id.
so? You suggest modifying the wysiwyg editors code to ensure that I can set ID's for the iframe and its message body is the best way to go ditching what I have so far? What I have kinda works, Just doesnt Update the value of the hidden field in source, but it does on screen... Is it because I have this using tagnames rather than via ID's that I have this problem? Thanks in advance
I've added id's and now accessing the Iframe the way you suggested. But it doesnt seem to work at all now?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.