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.

3
  • Source of the iframe from the same domain of the parent page? Commented Dec 22, 2011 at 20:10
  • Same domain, different sub domain?? Does that matter? Commented Dec 22, 2011 at 20:11
  • Can you modify the page being loaded in the <iframe>? Commented Dec 22, 2011 at 20:25

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.