I’m generating iframes dynamically for a lot of different random websites, and I tend to get this error in my javascript console (not necessarily with this url):
Unsafe JavaScript attempt to access frame with URL http://localhost:3000/results/ from frame with URL http://www.apple.com/iphone/. Domains, protocols and ports must match.
Why am I getting this error? Is there a way to get rid of it?
So the only two times I interact with iframes in javascript is when I dynamically load in an iframe:
$("#results_div").html('<iframe src='+url+' frameborder="0" class="iframe"><p>Browser does not support iframes.</p></iframe>');
and when I pull the src attribute of an iframe:
var previewed = $("iframe").attr("src");
Which one is causing the error?
Script in your iframe is trying to access parent’s script/dom and they are in different domains. Cross domain scripting genrally generates that error.
In your case,
apple.comandlocalhostare different domains and something in those iframe is trying to access its parent window’s script or dom element.Couple of ways to solve this:
postmessage: http://ajaxian.com/archives/cross-window-messaging-with-html-5-postmessage