Snippets

Winni Neessen IFRAME access via JS

Created by Winni Neessen
<iframe id="foobariframe" src="https://www.heise.de" height="50" width="800"></iframe>

<script>//<![CDATA[
    document.onreadystatechange = function () {
        if(document.readyState === "complete"){
            // Using Vanilla JS
            console.log('Using querySelector');
            var querySelectIframe = document.querySelector('#foobariframe');
            if(typeof querySelectIframe === 'undefined' || querySelectIframe === null) {
                console.error('Unable to find iframe. Aborting');
                return false;
            }
            console.dir(querySelectIframe);
            
            // Using bloated jQuery
            console.log('Using jQuery');
            console.dir($('#foobariframe').contents())
        }
    }//]]>
</script>

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.