views:

611

answers:

2

Hi. I'm looking for a way to access read-only properties of a page on a IFRAME. Specifically I would like to read the selection. Apparently I can't read it because the document lies on another domain.

Is there a way to read them?

+1  A: 

I've used document.domain to solve this problem in the past. You can only use this, though, it the iframe and outer page share the same domain, i.e. www.example.com and ifrm.example.com. I've also heard of something called JSONP which apparently solves this problem even if there is no shared domain. Mmany Google API's use this.

crizCraig
A: 

your browser wont allow you to access anything that lives on another domain. you are out of luck.

as far as JSONP goes, that is one way to get around cross domain problems. the way it works in a nutshell is you pass it a javascript function name, and some request, and it returns a json object that is wrapped inside your function like:

myfunction({some:"crazy", "object":2});

when you make this request, you stick the response of it into a script tag, which in turn is executed on load, calling your "myFunction" which must exist on your side of things.

this only works if the server supports JSONP. if it returns plain JSON, as many of them do you cant use it in javascript.

mkoryak