Brad Herman
Brad Herman

Reputation: 10621

iFrame click monitoring from parent

We have a client who needs us to include a tool in their site via iFrame. Within the iFrame, we are displaying products and when the "add to cart" link is clicked, it needs to add the product to the parent documents cart. The parent and child are not on the same domain. Unfortunately, the client can't provide us with a method to post to the cart and all we can do is call their cart.add(qty,id) function, but it won't work within the iFrame because the iFrame obviously doesn't have the function available. In addition, we can't just fake the post to cart as we can't access the session id. Luckily I can add whatever Javascript I need to their main page.

Is there a way for me to listen for clicks in the iFrame from the parents, then to pull the quantity and product id values from within the iframe, then execute the cart.add function? Is there a better way to approach this given the constraints?

Upvotes: 1

Views: 1474

Answers (3)

lupos
lupos

Reputation: 374

dont use an iFrame. use jquery .load() to place the whole other site within a div. Make sure your "clicks" are live() so they catch clicks on the added content and it should be fine. I dunno how huge the site your loading in is. Also with load you can specify just a chunk of the page to bring in so just or a specific div if you don't need all the header info.

Upvotes: 0

Mark Keats
Mark Keats

Reputation: 1400

This isn't possible as it's a security risk and is prevented by the same-origin policy.

Upvotes: 3

Related Questions