1

OK, there have been a lot of discussions on this topic, but I haven't quite found an answer (see Unsafe JavaScript attempt to access frame in Google Chrome, Unsafe JavaScript attempt to access frame with URL for example).

Here's my situation:

I've got a file called index.html that looks like this:

<frameset>
   <frame src="a">
   <frame src="b">
</frameset>

Then 'a' looks like this:

<script language='javascript'>document.domain = document.domain</script>
<img src='whatever.jpg' id='foo'/>

And 'b' looks like this:

<script language='javascript'>
<!--
setTimeout(function() {
document.domain=document.domain
document.write('top domain is ' + document.domain)
  document.domain = document.domain
  top.a.document.images['foo'].src = 'something.jpg'
}, (5 * 1000));
//-->
</script>

So in a nutshell: a is a frame with a single image in it. b is a frame that should automatically change the src attribute of a's image link. But Chrome is unhappy!

(Note that I added the "document.domain=document.domain" lines pursuant to comments below).

(Also, note that the 5 second delay in frame 'b' is necessary to get a valid-looking URL for the call.)

According to the Chrome js debugger, this is causing a "unsafe javascript attempt to access url". Based on the other discussions of this error on Stack Overflow, it's unclear to me if there are any conditions under which I'm allowed to do this. These files (index, a, b) are entirely local on my machine. So there shouldn't be any concerns about them coming from different domains.

Any ideas? Sorry for re-posting, but I've quite found a definitive answer...

Community
  • 1
  • 1
Stephen Gross
  • 5,274
  • 12
  • 41
  • 59
  • See http://stackoverflow.com/questions/1481251/what-does-document-domain-document-domain-do - Cross frame/iframe requires document.domain be explicitly set in all frames. – broofa Oct 17 '11 at 16:39
  • andy e: Can you explain further? Not quite sure I understand the routine...? – Stephen Gross Oct 17 '11 at 16:44
  • Looking at the discussion on http://stackoverflow.com/questions/1481251/what-does-document-domain-document-domain-do, it's not quite the answer to my problem. I've tried adding the recommended domain-setting, and still no dice. – Stephen Gross Oct 17 '11 at 17:06
  • I'm not sure that this is an exact duplicate of the other issue. In my case, I'm running this thing entirely as local files; the other post seems to apply to people running actual web servers. – Stephen Gross Oct 17 '11 at 17:29

0 Answers0