get parent iframe element from inner page without knowing id

Parent html

			<iframe src="test.html" hash="r4d5f7"/>
			<iframe src="test.html" hash="8f7x97"/>
			<iframe src="test.html" hash="gg4v5e"/>
			<iframe src="test.html" hash="e54f87"/>

iframe html

function getHash()   {
           var ifs ="iframe");
           for(var i = 0, len = ifs.length; i < len; i++)  {
              var f = ifs[i];
              var fDoc = f.contentDocument || f.contentWindow.document;
              if(fDoc === document)   {
		<h1 id="goodid">good</h1>
	<button onclick="getHash()">Click me</button>

This code works in FF and IE6, Opera, Chrome (requires a web server and both files coming from same domain protocol and port)


In my case, i need to use this in the gwt, so i have to replace the fDoc===document with fDoc===$wnd.document or $doc.

More detail in this POST.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s