Sandip's Programming Zen

An attempt to share tech/coding experiences

Cross-Domain Calls with IFrames

with 2 comments

We know that cross domain ajax calls are not possible from javascript, but come’on we live in virtual world and every law can be bent if we can (remember Morpheus from ultra cool Matrix 😉 )

Ok, I found  here on this nice guy’s blog under Cross-Domain Communication with IFrames.

I have actually used it and it works like a charm. I made a simple javascript function to get the anchor values , actually I used anchors to pass values using URL as if passing URL variable.

For example if I want to pass one variable then I would do :

For two variables :

Two JS function, one for getting anchor value and second for resetting URL to it’s original form.

function getAnchor(name) {

url = window.location.href;
var varlen = name.length + 2;
var start = url.indexOf(“#” + name) + varlen;
var length = url.indexOf(“#”, start) – start;

var value = url.substr(start, length);
return value;

function resetAnchor() {
url = window.location.href;
var hash = url.indexOf(“#”)
if (hash >= 0) {
url = url.substr(0, hash);
window.location.href = url + “#”;

I would be happy to help if you have any troubles.

Written by Sandip

April 29, 2009 at 4:37 pm

Posted in Internet, Javascript

Tagged with ,

2 Responses

Subscribe to comments with RSS.

  1. Nice 🙂 this is usefull, thanks for posting this!


    May 12, 2009 at 2:56 pm

  2. Oh man, I have been looking for this for so long trying to find a solution to get my iframe on one domain to communicate with my app on another domain, so it auto-adjusts the height.

    I’m trying to implement your code, but to be quite honest I’m not exactly sure of what code goes where and how to make it interact properly.

    Can you please help me with my issue? I would be so appreciative. Just email me at the provided email.



    September 16, 2009 at 3:36 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: