2

I am working on a project in drupal in which i have an iframe loaded in another website.

I need to get the url from the address bar.

e.g., lets say i have a website embedded in the iframe as example.com...and another site embedding this iframe has the domain as abcd.com

So, the url that gets formed on accessing any content in the iframe would be like.. abcd.com/#/

I need to get this URL in the iframe.

Please help me resolving this problem. I am tryin to write a custom module for this but dunno how to proceed.

Piyuesh Kumar
  • 436
  • 5
  • 21

2 Answers2

0

In your iframe you could add a variable to the iframe url and use drupal 'current_path' to get the url of the iframe's parent. Then you could retrieve this variable from your iframe page(and make sure you validate it before you use it). i.e.

www.iframsite.com/iframepage?from=<?php print current_path(); ?>
Sudipta
  • 4,773
  • 2
  • 27
  • 42
farse311
  • 31
  • 3
0

You cannot access the URL of an iframe from the outside. Think about potential XSS attacks that could occur from that:

http://yourbankingsite/account?sessid=2239872379092FEAACC2390823

Of course, this is a bad way to store the session id, but there are quite a few (and popular) sites that do this. If you had access to the iframe URL, a malicious website could be nothing but said iframe and a script to harvest the session ID.

CassOnMars
  • 6,153
  • 2
  • 32
  • 47