views:

162

answers:

1

Hi.

I have a 'toolbar' that displays some code on the top of the window, and then I load an iframe with an external site. I realize that I can't get the active link the user is on because it would be a violation of same origin policy.

Is there any way (using greasemonkey maybe?) that I could get the active url of the external iframe?

I need to do this for demo purposes, not for anything practical. (I realize the real solution would be to process the entire page through my own server)

Thanks!

A: 

I'll post a workaround that I wrote: If you install greasemonkey, write a script does (roughly) something like this:

current_link = document.location.href;
if(current_link !== 'http://my_local_site')
{
   GM_setVal("link", current_link); }

Have greasemonkey run this script on your iframe's URL and on your local site and on your iframe's site. GM will save to its internal memory the link. If you don't trigger the IF statement, you're probably reading the script from your local site, ergo you need to:

unsafeWindow.urlVal = GM_getVal("link");

All you need to do now is to get both the local frame and the iframe to run the script every time a page is navigated on the iframe. You can get this done on your local frame by a) timing it b) using some type of event trigger. Best of luck!

daniel