html – How can I manipulate text through an iframe? – Education Career Blog

I have two questions. This is core component of a project I’m currently working on. I’m looking for a way to manipulate/edit the source code of an iFrame whose “src” will always be changing: a dynamic iFrame. Is this possible? I know that it’s really not recommended because of the potential security issues.

And my other question is: Is it possible to retrieve the selected text inside a iFrame that’s also dynamic?

I’ve searched for answers on Google, and found no results. Please help me. 🙂


An iframe is just another webpage inside the one you are looking at. It has the same javascript functions and methods a normal webpage has.

To access it:

document.getElementById('iframeID').contentDocument (DOM)

Look here for cross-browser access:

And here for getting the selected text:

Combining them:

document.getElementById('iframeID').contentDocument.getSelection(); (DOM)

As for manipulating source code, I don’t know what you want to do, but Javascript (jQuery) may be the best choice.

Leave a Comment