views:

955

answers:

4

Hi Everyone,

I've been at this for several days and searches including here haven't give me any solutions yet.

I am creating a Bookmarklet which is to interact with a POST API. I've gotten most of it working except the most important part; the sending of data from the iframe (I know horrible! If anyone knows a better solution please let me know) to the javascript on my domain (same domain as API so the communication with the API is no problem).

From the page the user clicks on the bookmarklet I need to get the following data to the javascript that is included in the iFrame.

 var title = pageData[0].title;
 var address = pageData[0].address;
 var lastmodified = pageData[0].lastmodified;
 var referralurl = pageData[0].referralurl;

I first fixed it with parsing this data as JSON and sending it through the name="" attribute of the iFrame but realized on about 20% of webpages this breaks. I get an access denied; also it's not a very pretty method.

Does anyone have anyidea on how I can solve this. I am not looking to use POSTS that redirect I want it all to be AJAX and as unobtrusive as possible. It's also worth noting I use the jQuery library.

Thank you very much,

Ice

A: 

If you need to pass data to the iframe, and the iframe is actually including another page, but that other page is on the same domain (a lot of assumptions, I know).

Then the man page code can do this:

DATA_FOR_IFRAME = ({'whatever': 'stuff'});

Then the code on the page included by the iframe can do this:

window.parent.DATA_FOR_IFRAME;

to get at the data :)

singpolyma
+1  A: 

After a lot of work I was able to find a solution using JSONP which is enables Cross Domain Javascript. It's very tricky with the Codeigniter Framework because passing data allong the URLs requires a lot of encoding and making sure you dont have illegal characters. Also I'm still looking to see how secure it really is.

A: 

If I understand your question correctly, you might have some success by looking into using a Script Tag proxy. This is the standard way to do cross domain AJAX in javascript frameworks like jquery and extjs.

See Jquery AJAX Documentation

Jonathan Soeder
A: 

You should look into easyXDM, it's very easy to use. Check out one of the examples on http://consumer.easyxdm.net/current/example/methods.html

Sean Kinsey