简体   繁体   中英

How can a user retrieve the current iFrame URL (cross-domain)

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.

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 !

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM