0

I have a script which handles something in content of the frames. I want to except iframe from another domains (cross-domains) or filter iframe of same domain.

function isCrossDomain(ifr) {
    // what i need
    // Return true or false
}


if (! isCrossDomain(ifr)) {
    var doc = ifr.contents();
}
anhtran
  • 2,006
  • 4
  • 27
  • 53
  • http://blog.cakemail.com/the-iframe-cross-domain-policy-problem/ – Robert Harvey Sep 16 '13 at 05:01
  • Check this [link](http://stackoverflow.com/questions/44359/how-do-i-get-the-current-location-of-an-iframe), it looks like if you reference the href of a domain that is not your own it will raise an exception. This exception could be all you need to write your function. – rfoo Sep 16 '13 at 05:03

2 Answers2

0
<iframe name="myFrame" id="myFrame" src="child.html" style="height: 50%; width: 50%;" onload="checkForCross()"></iframe>

function checkForCross()
{
  var iframe = document.getElementById("myFrame");
  var loc = iframe.contentDocument.location.href;

}
Vaibs_Cool
  • 6,126
  • 5
  • 28
  • 61
0

I hope I am understanding you correctly. Just collect the iframes that match your conditional. Lets just say in this case, its yourdomain.com

Once you have your collection of matches, then you can extract the contents() from them.

You can create a regex to capture the match you want.

var iFRMS = jQuery('body').find('iframe').map(function(n, i){
   if (jQuery(i).prop('src').match('yourdomain.com')){
      return this;
   }
});
james emanon
  • 11,185
  • 11
  • 56
  • 97