This page is a sample page in response to this question on stackoverflow:

What is the way to access IFrame's element using Prototype $ method?:

This is the code of the iframe:

<iframe src="frame.html" id="iframeID"></iframe>

This is the JavaScript code that is loaded on this page:

// This is a shortcut handler for elements inside an
// iframe with the id "iframeID":
var $IFRAME = function (id){
    return $('iframeID').contentWindow.document.getElementById(id);
}
// Prototype onload handler:
Event.observe(window, 'load', function(){
	// style the paragraph
	Element.setStyle($IFRAME('p1'), {
		border:'1px solid #c00',
		backgroundColor:'#ccc'
	});

	// add some content
	Element.insert($IFRAME('p1'), {after:'And this is text added with Prototype from the enclosing page.' });

	// (this is what loads the javascript on this page for display)
	var sourceCode = $$('script')[1];
	$('code').innerHTML = sourceCode.innerHTML;
});
blog comments powered by Disqus