4

I want to know if it is possible to add a javascript <script type="text/javascript">blahblah</script> to an iframe OR frameset that is on the page?

Just a note: the content comes from the same domain www.domain.com but the subdomain is different www.blah.domain.com vs www.blah2.domain.com, I'm not sure if that matters.

Steven
  • 13,250
  • 33
  • 95
  • 147

1 Answers1

2

It does matter but luckily there's a fairly simple fix. You just need to set the document.domain property on both sides to the same domain (e.g., document.domain = 'domain.com')

document.domain can only be set to the same super domain so you couldn't do this with www.example.com and blah.example2.com.

Once you have the document.domain property set you should be able to interface the iframe the same way you would if they were on the same subdomain.

Here's how to insert the script tag into the iFrame: Insert a Script into a iFrame's Header, without clearing out the body of the iFrame

Community
  • 1
  • 1
JaredMcAteer
  • 21,688
  • 5
  • 49
  • 65