0

I'm inserting an iframe to display another website's content in mine, and I'd like to clean it up first. So I tried to use $('iframe').contents, but the return is undefined, while $('iframe') works like a charm. Is there some kind of cross site security here ?

Bonus question : how should I clean the page then ? I just need div#main, not the rest. I'm using an iframe so I can get the original styling.

Thanks for your time

1

2 Answers 2

4

Is there some kind of cross site security here?

Yes, the Same Origin Policy.

There aren't many ways around it - I once used PHP to fetch the contents of the target webpage and write them locally, but that was quite a specific thing (and I owned both domains).

Take a look at this question: jQuery cross domain iframe scripting

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

1 Comment

Getting the content of the target page is actually not an issue and very easy to do with ruby/nokogiri. I try not to use iframes, but in this case, it was useful in order to have a nice rendering without putting effort in it. Anyway, thanks to you & Linus below.
2

It's called Same-Origin Policy. Basically, you can't use javascript to interact with pages from another domain (protocol, domain and port must all match).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.