1

TL;DR : How can a user copy the current URL of an iFrame (cross-domain) ?

I want to insert in a webpage of my domain an iFrame to be able to browse other partner websites (different domains). When the user finds the page he is interested in, he needs to transfer the information (URL of the page) to my website somehow. It is fine to ask the user to do it manually, I'm just looking for the more convenient way to do that.

I am aware that cross-reference scripting restrictions to prevent XSS attacks limit what you can do with an iFrame & javascript.

I have looked at questions like this one, but the answers seem old, and from what I understand they are all trying to automatize this process with javascript, but in my case I don't need that

EDIT :

I accept a manual solution for the user. ie, a browser-specific procedure (a solution that works on Firefox/Chrome would be fine). For example, it's possible to have a look at the browser history... but I'm looking for better solutions.

Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164
  • 1
    possible duplicate of [Get current URL from IFRAME](http://stackoverflow.com/questions/938180/get-current-url-from-iframe) – Hayden Schiff Aug 13 '15 at 15:11
  • 1
    The answers that say it's not possible if the domains differ are still correct. It's not likely that this will ever happen because it'd simply be too big of a security issue. – Hayden Schiff Aug 13 '15 at 15:16
  • @oxguy3 Alright, I edited my post to clarify that, but could you provide a manual solution for the user ? The page IS displayed in the user's browser, so there definitely IS a way to get the current URL (via the browser). It is NOT a duplicate of the question you mentionned. – Cyril Duchon-Doris Aug 13 '15 at 18:01
  • @oxguy3 Ah... actually I believe this question rather belongs to superuser instead of StackOverflow... Though I would love if there was a way to program some sort of browser code to copy an iFrame current URL in the clipboard. – Cyril Duchon-Doris Aug 13 '15 at 21:23
  • Hey, are you sure your info is still up-to-date ? What about CORS ? – Cyril Duchon-Doris Aug 14 '15 at 14:03

2 Answers2

0

Some stuff I found

Firefox

Browser history

All URLs browsed inside iFrames will still be added to the browser history

Element info

When right-clicking the iFrame, there is an additional submenu that opens in firefox (in French called "ce cadre", must be something like "this frame" in english). Then you can click on "information for this frame", and it will show many info including the URL.

I'm still looking for more convenient ways to retrieve the URL. Ideally, a shortcut would be nice !

Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164
-4

You should be able to do something like this

jQuery("iframe").get(0).contentWindow.location.origin

Use jQuery to find the desirable iframe then use .contentWindow.location.origin to get the URL.

musically_ut
  • 34,028
  • 8
  • 94
  • 106
brunof
  • 1
  • 3